Page tree
Skip to end of metadata
Go to start of metadata
Help on any Linux command.
man command 
Type man ls to read the manual for the ls command. 
List/Change to/Make/Remove directory
ls path 
It’s ok to combine attributes, e.g. ls -laF gets a long listing of all files with types. 
ls -l path 
Long listing, with date, size and permissions. 
ls -a path 
Show all files, including important .dot files that don’t otherwise show. 
cd dirname 
There must be a space between. 
cd ~ 
Go back to home directory, useful if you’re lost. 
cd .. 
Go back one directory. 
Show where you are as full path. Useful if you’re lost or exploring. 
mkdir dirname 
Make a new directory 
rmdir dirname 
Only works if {dirname} is empty. 
rm -r dirname 
Remove all files and subdirs. Careful! 
Copy/Move/Rename/Delete a file or directory
cp file1 file2 
Copy file1 to file2. 
cp -r dir1 dir2 
Recursive, copy directory and all subdirs. 
mv oldfile newfile 
Moving a file and renaming it are the same thing. 
mv oldname newname 
rm filespec 
remove files. “?” is any character; “*” is any string of characters. 
Connect/Copy files to remote host
ssh user@host 
Secure login to remote host 
scp file user@host:destination 
Secure copy to remote host 
View/Edit a text file
less filename 
View file one screen at a time. 
cat filename 
View file, but it scrolls. 
vim filename 
edit a file with vim 
emacs filename 
edit a file with emacs 
Compress files
tar czf file.tar.gz files 
create a tar with Gzip compression containing files (use xzf to extract) 
gzip file 
compresses file and renames it to file.gz 
Compare two files
diff file1 file2 
Show the differences. 
sdiff file1 file2 
Show files side by side, and the difference are indicated by symbols "< > |"
Other text commands
grep 'pattern' file 
Find regular expression in file. 
sort file1 > file2 
Sort file1 and save as file2. 
uniq file 
Report or omit repeated lines. 
awk '{print$4}' file 
Print the 4th column of the file. 
wc file 
Count words in file. 
Find files on system
find filespec 
Works with wildcards. Handy for snooping. 
Make an Alias
alias name 'command' 
Put the command in ‘single quotes’. More useful in your .login or .profile file. 
Wildcards and Shortcuts
Match any single character, eg page? gets page1 and page2, but not page10. 
Match any characters in a range, eg page[1-3] gets page1, page2, and page3. 
Short for your home directory. e.g. cd ~ will take you home, rm -r ~ will destroy it. 
The current directory. 

One directory up the tree, e.g. ls ..

Pipes and Redirection
command > file 
Redirect output to a file, e.g. ls > list.txt writes directory to file. 
command >> file 
Append output to an existing file, e.g. cat update >> archive adds update to end of archive. 
command < file 
Get input from a file, e.g. sort < file.txt
command | command 
Pipe one command to another, e.g. ls | less gets directory and sends it to less to show. 
halts the current command. 
stops the current command, resume with fg (foreground) or bg (background). 
log out of current session, similar to exit.