Last updated: 2026-07-21
Linux Command Line
Get Help
- [command] --help or -h : get help
- man : display the online manual
- man -k <search_term>
- <enter> down, <space> down page, g-top,G-bottom, q-quit, /:search, ?: search back, h:help
Navigate
- Space : can escape spaces, or use quote
- ls : list all files and folders of current working directory
- ls -l : check permission
- ls -a : all hiden and unhiden files
- ls -al : combine
- ls -F: reveal file types
- -t : list by time
- -r : reverse order (common: -latr)
- -R : list recusrively
- --color : colorize
- tree : visual ls -R
- -d: directories only
- -C colorize output
- cd <directory> : change directory
- current directory is short for "."
- parent directory is".."
- previous directory is "-"
- home directory "~"
- pwd - present working directory
Edit
- mkdir <directory> : make new directory in current directory
- cp <source> <destination> : copy
- cp - r <source> <destination> : copy all files in source ( r is "recursive")
- cp -i : run in interactive mode
- rm <file> : remove the file
- rm -f <file> : remove and skip the confirmation
- rm -r <directory> : remove the whole directory (recursive)
- rm -rf <directory> : combine above two
- rm < source> <destination> : rename the source
- rmdir
- mv <source> <destination>
- -i: interactive mode
- touch [option] <filename>: create new empty file
- tar [-] c|x|t f [file]<tarfile> [pattern]: create, list or extract contents of a tar archive following patterns (if supplied)
- c: create tar archive
- x: extract files from archive
- t: display table of contents
- v: be verbose
- z: use compression ( create tgz)
- -f file: the tar file to operate against
- eg.tar acf tps.tgz tpsreports, tar tf tps.tar
- gzip: compress files
- gunzip: uncompress files
- gzcat: concatenates compressed files
- zcat: concatenates compressed files
- cat <filename> [file name2] > [new file name] : concatenates and display files
- more <fileame>: browse through the file, <space> to enter, q to quit
- less <file>: enable backward movement and pattern searches on more
- head [-#] <file>, tail [-#] <file>: view head and tail (# lines)
- tail -f [file]: follow line in real time
- diff <file1> <file2> : compare files
- sdiff: side-by-side
- vimdiff: highlight in vim
- Crtl-w w: go to next window
- :q quit, :qa quit all, :qa!
- sort <file>: sort text in file
- sort -k <F> <file>: sort by key, F is the field number
- sort -r: sort reversely
- sort -u: sort unique
- du: estimates file usage
- du -k: display in kilobytes
- du -h: display in human readable format
- cut <file> : cut selected portions of a file
- tr
Search
- find [path...] [options] [expression] : recursively finds files in path, default path is pwd
- -name matchname
- -iname case-insensitive name
- -ls perform ls on each found one
- -mtime <days> that days old
- -size <size>
- -newer <file> newer than file
- -exec <command> {} ; execute command on all found ones
- locate [pattern]: faster, but not in real-time
- grep <pattern> [file]: global regular-expression: display pattern matches a file
- -i: ignore case
- -c: count the number of occurrences in a file
- -n: precede output with line numbers
- -v: invert match
- file <file>: display file type
- strings: display printable strings
- where <command>:find the binary file of command
Pipes
<command-output> | <command-input> : use output of command as another input
Wildcards
- *: matches zero or more char
- *.txt, a*.txt,
- ?: matches one char
- [] : match one of eg. [aeiou]
- [!]: matches not char
- [a-e], [3-6]: matches range
- named classes
- [[:alpha:]]
- [[alnum:]] (alpha-numeric: letters and decimal digits)
- [[:digit:]]
- [[:lower:]], [[:upper:]]
- [[:space:]], space, tab - all white space
- <wildcard> : escape: match a wildcard
- can work with any command with parameter <filename>