-
pwd (print working directory)
- ls (list)
#without argument curr directory ls #with argument ls DIRECTORY
- cd (change directory)
#without argument home directory cd #with argument cd DIRECTORY # back cd ..
- mv (move or rename)
#move mv FILE_OR_DIRECTORY_NAME NEW_DIRECTORY #rename mv FILE_OR_DIRECTORY_NAME NEW_FILE_OR_DIRECTORY_NAME
- cp (copy)
#same directory cp ORIGINAL_FILENAME NEW_FILENAME #another directory cp ORIGINAL_FILENAME DIRECTORY #copy directory cp -r ORIGINAL_DIRECTORY NEW_DIRECTORY
- cat (concatenate - prints the contents of a file)
cat FILENAME
- rm (remove)
#delete rm FILENAME #delete all rm * #non-empty directory rm -r DIRECTORY_NAME
- mkdir (make directory)
mkdir DIRECTORY_NAME
- rmdir (remove directory)
rmdir DIRECTORY_NAME
- print n lines
#print n lines head -n 2 FILENAME tail -n 2 FILENAME #combine head -n 20 FILENAME | tail -n 5 #watch the file update tail -f FILENAME
- show history
#show history history
- clear screen
#clear screen clear
- install / update packages
#install sudo apt-get install packagename #update sudo apt-get update
- grep <str> <files> (Find which files contain a certain word)
grep "some word" *
- chmod <opt> <file> (Change file permission)
#Change file permissions read only chmod 644 *.html
- ps <opt> (List running process)
#List all running processes by #ID ps aux #List process #ID's running by dhyatt ps aux | grep USERNAME
- kill <opt> <ID> (kill a process)
#Kill process with ID #8453 kill -9 8453
- gzip <file>
#Compress file gzip bigfile #Uncompress file gunzip bigfile.gz
- awk (Pattern search, replace and more)
#Print the lines which matches with the given pattern. awk '/someword/ {print}' FILENAME #Print 1st and 4th column awk '{print $1,$4}' FILENAME #Replace comma by null in 3rd column awk '{ gsub(",","",$3); print $3 }' FILENAME
- diff (Compare files)
diff FILENAME1 FILENAME2
- at (Scheduling a job)
#Schedule a job echo "sh backup.sh" | at 9:00 AM echo "sh backup.sh" | at now + 30 minutes #List the scheduled jobs using atq atq #Remove scheduled job using atrm atrm 3
- more / less (pagination tool for viewing text files)
cat FILENAME | more
-
date (print current date)
- & (the & informs the shell to put the command in the background)
sh shell_script.sh &
- nohup (prevents the command from being aborted automatically when you log out or exit the shell)
nohup sh shell_script.sh -y &
- Download a file with wget
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
- Download a file with curl
curl -fsSL -o Miniconda3-latest-MacOSX-x86_64.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
Leave a Comment