Common Terminal Commands
OverviewThis guide provides a comprehensive list of essential terminal commands, organized by categories like navigation, file management, and more. Perfect for beginners and advanced users alike.
Key Commands & Navigation
TIPKeyboard shortcuts can save time when navigating and using the terminal.
Up Arrow
: Will show your last commandDown Arrow
: Will show your next commandTab
: Will auto-complete your commandCtrl + L
: Will clear the screenCtrl + C
: Will cancel a commandCtrl + R
: Will search for a commandCtrl + D
: Will exit the terminal
Manual Command
Usingman
CommandThe
man
command displays manuals for commands on Linux and MacOS. Use--help
for similar functionality on Git Bash.
man ls
On Git Bash or Windows:
ls --help
The whoami
Command
Identify Current UserThe
whoami
command displays the current logged-in user.
whoami
The date
Command
Get Current Date & TimeThe
date
command shows the current date and time.
date
File System Navigation
Essential Navigation CommandsFile system navigation is fundamental to terminal usage.
Command | Description |
---|---|
pwd | Lists the path to the working directory |
ls | List directory contents |
ls -a | List contents including hidden files (Files that begin with a dot) |
ls -l | List contents with more info including permissions (long listing) |
ls -r | List contents reverse order |
cd | Change directory to home |
cd [dirname] | Change directory to specific directory |
cd ~ | Change to home directory |
cd .. | Change to parent directory |
cd - | Change to previous directory |
find [dirtosearch] -name [filename] | Find location of a program |
Combine flags, e.g., ls -la
to view detailed and hidden files.
Opening a Folder or File
Open Directories, Files, or URLsCommands differ across operating systems for opening files, folders, or URLs.
- Mac:
open [dirname]
- Windows:
start [dirname]
- Linux:
xdg-open [dirname]
open https://example.com
Modifying Files & Directories
File & Directory Management CommandsLearn to create, delete, move, and rename files and directories.
Command | Description |
---|---|
mkdir [dirname] | Make directory |
touch [filename] | Create file |
rm [filename] | Remove file |
rm -i [filename] | Remove file with confirmation |
rm -r [dirname] | Remove directory |
rm -rf [dirname] | Force remove directory |
rm ./* | Remove everything in the current folder |
cp [filename] [dirname] | Copy file |
mv [filename] [dirname] | Move file |
mv [filename] [filename] | Rename file |
Create nested directories:
mkdir -p ./home/{a,b}/{x,y,z}
Run multiple commands:
cd test2 && mkdir test3
Right Angle Bracket >
Redirect OutputRedirect command output into a file.
> [filename]
Exit with Ctrl+D
.
The cat
Command
Concatenate Files
cat
displays or creates files and combines them.
cat [filename]
cat > [filename]
cat >> [filename]
Show line numbers:
cat -n [filename]
The less
Command
View File ContentsScroll through a file with
less
.
less [filename]
Exit with q
.
The echo
Command
Display Text or Write to FilesEcho text to the terminal or files.
echo "Hello World"
echo "Hello World" > [filename]
The nano
Command
Edit Text Files
nano
is a user-friendly text editor.
nano [filename]
Exit with Ctrl+X
. Save with Y
.
The head
and tail
Commands
View File PartsDisplay the start (
head
) or end (tail
) of files.
head -n 5 [filename]
tail -n 5 [filename]
The grep
Command
Search File ContentSearch for text patterns in files.
grep [searchterm] [filename]
The find
Command
Locate Files or DirectoriesSearch files by name, pattern, or properties.
find [dirname] -name [filename]
Create test files:
touch file-{001..100}.txt
find . -empty
Remove files:
find . -name "file-*" -delete
Piping
Redirect OutputPipe the output of one command to another.
find . -name "file-0*" > output.txt
cat output.txt
Creating a Symlink
Create ShortcutsCreate symbolic links to files.
ln -s [filename] [symlinkname]
Remove with:
rm [symlinkname]
File Compression
Manage ArchivesCreate and extract tarballs with
tar
.
Command | Description |
---|---|
tar czvf [dirname].tar.gz [dirname] | Create tarball |
tar tzvf [dirname] | View tarball contents |
tar xzvf [dirname].tar.gz | Extract tarball |
The history
Command
Command HistoryView and execute past commands.
history
!100
Run the 100th command in the history.