Useful Linux commands and their arguments
๐ธ cd /directory moves the present working directory to one specified
๐ธ cp /copied_item /target copies a filed or directory to a target directory. If your copying a directory use cp -rf . .
๐ธ pwd shows the absolute path of where you are (present working directory)
๐ธ chmod ### file how you give or remove access to files. first digit is you, second is group and last is all users
(read=4,write=2,execute=1. ex: use 777 for full access to everyone)
๐ธ diff /file /file outputs the lines that do not match between the two files
๐ธ rm file remove command lets you remove a file. Removing a directory requires -rf (ex: rm -rf dir)
๐ธ mkdir directoryname makes a directory with the name specified
๐ธ touch filename makes a file with the name specified
๐ธ mv file file lets you move a file somewhere else and is also used to rename files
๐ธ cat file displays the text of a file
๐ธ man "command" displays the manual for the command specified. Useful to find options for the command quickly
๐ธ history shows the commands you've entered
๐ธ ctrl+c quits you out of most programs
๐ธ | this symbol is called "pipe" and is used to feed output of one command into another command without
storing it into a variable (ex: "ls -s | head -5" takes the list of files ordered by size from ls and prints the top 5 of them)
ls commands $ ls [options] [file|dir]
๐ธ ls -a list all files including hidden file starting with '.'
๐ธ ls --color colored list [=always/never/auto]
๐ธ ls -d list directories
๐ธ ls -i list file's inode index number
๐ธ ls -l list with long format - show permissions
๐ธ ls -la list long format including hidden files
๐ธ ls -lh list long format with readable file size
๐ธ ls -ls list with long format with file size
๐ธ ls -r list in reverse order
๐ธ ls -R list recursively directory tree
๐ธ ls -s list file size
๐ธ ls -S sort by file size
๐ธ ls -t sort by time & date
๐ธ ls -X sort by extension name
grep commands grep [options] pattern [files]
๐ธ grep -c This prints only a count of the lines that match a pattern
๐ธ grep -h Display the matched lines, but do not display the filenames
๐ธ grep -i Ignores, case for matching
๐ธ grep -l Displays list of a filenames only
๐ธ grep -n Display the matched lines and their line numbers
๐ธ grep -v This prints out all the lines that do not matches the pattern
๐ธ grep -e exp Specifies expression with this option. Can use multiple times
๐ธ grep -f file Takes patterns from file, one per line
๐ธ grep -E Treats pattern as an extended regular expression (ERE)
๐ธ grep -w Match whole word
sed commands sed [option] 'command' [input-file]
๐ธ sed '/^$/d' Remove all whitespace
๐ธ sed 's/Sonday/Sunday/' weekday.txt
๐ธ sed -i When option, edit source file directly. Also used to ignore case when flag
๐ธ sed -g Edit every occurence
๐ธ ^ Acts like a special character and matches at the beginning of the regular exp
๐ธ $ Acts like a special character and matches at the end of the regular exp
๐ธ . Matches any single character, even including a new line
๐ธ * Matches the sequence of zero or more instances of the previous character
๐ธ sed 's/Linux/Unix/' linuxteck.txt (first occurence in each line)
๐ธ sed 's/Linux/Unix/2' linuxteck.txt (Second occurence in each line)
sort commands sort [OPTION]... [FILE]...
๐ธ sort -b Remove all whitespace
๐ธ sort -d Consider only blanks and alphanumeric characters
๐ธ sort -f Fold lower case to upper case characters
๐ธ sort -g Compare according to general numerical value
๐ธ sort -i Consider only printable characters
๐ธ sort -n Compare according to string numerical value
head commands head [OPTION]... [FILE]...
๐ธ head -n # Print number of lines from top down
๐ธ tail -# prints last # of elements (lines/files)