HomeAbout

Commands

Running Shell Script

./script_name.sh # OR sh script_name.sh # OR bash ./script_path.sh

Commands

# cat ## reads the contents of a file in console cat filename.txt ## override the contents of another file ### if the destination file does not exist, then the command will create the file cat source.txt > destination.txt ## concatenate multiple files to one cat source1.txt source2.txt > destination.txt # grep ## grep "search_string" filename

grep

By default, the grep command outputs entire lines that contain the match.

  • returns the lines of the text file which contain the matching search string.

A line in a text file is a sequence of characters followed by a line break.

List

# List contents of current directory ls # List ALL contents of current directory ## in default ls-style ls -a ## in vertical list style ls -la ## OR la

Search

Command line utility for searching plain-text data sets for lines that match a regex

grep

Rename OR Move (mv)

Rename

Change file's old_file_name to new_file_name in current directory

  • Also works for directory names
    • You should use gmv when you are inside of a git repository or Git will lose track of the changes (especially in directory with submodules)
mv old_file_name new_file_name

Move

When moving a directory, mv command also works

mv dir_name new_location/dir_name

Name with Spaces

Escape out the spaces with the \ escape character before the special character

# Moving "Learning Python Programming - Working Files" mv Learning\ Python\ Programming\ -\ Working\ Files

Copy

Copy the contents of a file or the output of a command to the system clipboard

# copying the contents of a file pbcopy < file.txt # copying the output of a command ls -l | pbcopy

Dot Command

Every directory in Unix-like OS contains (as a minimum), an object represented by a single dot and another represented by a double dot.

Single dot (.) represents the directory itself and the double dot (..) refers to its parent directory.

These dots are created in every directory.

.find

e.g. find and list all .DS_Store in current folder recursively

find . -name ".DS_Store"

Delete all files that are recursively matching from current directory.

  • -type f is a tag to filter only for files, excluding directories
find . -name ".DS_Store" -type f -delete

$home

Represents user's home directory regardless of where it is being called from.

  • Home can be different per OS (e.g. Mac and Linux have different home directories)

$home is same as ~.

std

top

top

Shows a dynamic, real-time view of running processes and kernel-managed tasks in Linux.

free

Check for memory RAM on your system or to check the memory statics of the Linux operating system.

In MacOS, the counterpart would be:

vm_stat

chmod

Sets the permissions of files and directories.

chmod u=rwx,g=rx,o=r myfile
  • the user can read, write, and execute it
  • members of your group can read and execute it
  • others may only read it

Filesystem level operations

# cp # The cp command allows you to duplicate files or directories from one part of the file system to another cp source_file_name target_file_name # zip # zips the destination path recursively to a single `.zip` file. zip [options] [file_name.zip] [files_names] # recursively zip files in path to a single file `output.zip` zip -r output.zip ./path-to-source
AboutContact