Commands
Update Linux
sudo apt dist-upgrade -y
Running Shell Script
./script_name.sh # OR sh script_name.sh # OR bash ./script_path.sh
File Level 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 cat file_name.txt | grep “keyword”
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.
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 gmvwhen you are inside of a git repository or Git will lose track of the changes (especially in directory with submodules)
 
- You should use 
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 fis 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.
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
# ls ls # list contents of current directory ls -a # list all contents in default ls-style ls -la # in vertical list style la # touch touch file_name.extension_name # create a new file # 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 # rm rm file_name # remove a file rm -r directory_name # remove a directory recursively rm -rf directory_name # forcefully remove a directory recursively # 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