Wiki > Bash Shell Commands
Legend
Everything in "<>" is to be replaced. Example: <filename> --> whatbox.txt
'..' means that more than one file can be affected with only one command.
Basic Terminal Shortcuts
CtrlL Clear the terminal
CtrlD Logout
CtrlA Move the cursor to the beginning of the line
CtrlE Move the cursor to the end of the line
CtrlU Delete left of the cursor
CtrlK Delete right of the cursor
CtrlW Delete the word to the left of the cursor
CtrlY Paste (after Ctrl U, K, or W)
CtrlR Reverse search history
CtrlZ Suspend a process to resume it later
!! Repeat the last command used
ShiftPage Up Scroll up in the terminal
ShiftPage Down Scroll down in the terminal
Alt. Copy the last argument of the previous command
Basic Terminal Navigation
ls -a List all files and folders
ls <foldername> List files in a folder
ls -lh Detailed list with a human-readable output
ls -l *.jpg List only jpeg files
ls -lh <fileName> Result for only a single file
cd <foldername> Change directory - If the folder name has spaces, use quotes. Example: cd "Folder With Spaces"
cd .. Go up one folder.
tip: ../../../
du -h Disk usage of folders in a human-readable output
du -ah Disk usage of files and folders in a human-readable output
du -sh Only show disk usage of folders
pwd Print the working directory
man <command> Shows the manual for a command or program
Basic file manipulation
cat <filename> Show the contents of a file (less, more)
head From the top
tail From the bottom
mkdir <foldername> Create a new folder
Example: mkdir stuff
Example: mkdir stuff/videos/ ..
cp image.jpg newimage.jpg Copy and rename a file
cp image.jpg <foldername>/ Copy to a folder
Example: cp image.jpg folder/image.jpg
cp -R folder1/ folder2/ Recursively (-R) copies folder1 and all of its contents into folder2.
mv file.txt documents/ Move a file to a folder
mv <folderName> <foldername2> Move a folder into a folder
mv filename.txt filename2.txt Rename a file
mv <foldername>/ .. Move a folder up in the hierarchy
touch <filename> Create or update a file
ln -s file1 file2 Symbolically link
More advanced tricks
Background a running process
If you start a process but need to close your terminal before it's completed, you may wish to background a process you're currently running. This can be achieved by executing the following three commands in sequence.
CtrlZ
bg
disown -h
Ctrl Z Suspends the process
bg resumes the process, but in the background
disown -h tells it to ignore the hangup signal (nohup)