494 words
2 minutes
Common Terminal Commands

Common Terminal Commands#

Overview

This 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#

TIP

Keyboard shortcuts can save time when navigating and using the terminal.

  • Up Arrow: Will show your last command
  • Down Arrow: Will show your next command
  • Tab: Will auto-complete your command
  • Ctrl + L: Will clear the screen
  • Ctrl + C: Will cancel a command
  • Ctrl + R: Will search for a command
  • Ctrl + D: Will exit the terminal

Manual Command#

Using man Command

The 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 User

The whoami command displays the current logged-in user.

whoami

The date Command#

Get Current Date & Time

The date command shows the current date and time.

date

File System Navigation#

Essential Navigation Commands

File system navigation is fundamental to terminal usage.

CommandDescription
pwdLists the path to the working directory
lsList directory contents
ls -aList contents including hidden files (Files that begin with a dot)
ls -lList contents with more info including permissions (long listing)
ls -rList contents reverse order
cdChange 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 URLs

Commands 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 Commands

Learn to create, delete, move, and rename files and directories.

CommandDescription
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 Output

Redirect 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 Contents

Scroll through a file with less.

less [filename]

Exit with q.

The echo Command#

Display Text or Write to Files

Echo 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 Parts

Display the start (head) or end (tail) of files.

head -n 5 [filename]
tail -n 5 [filename]

The grep Command#

Search File Content

Search for text patterns in files.

grep [searchterm] [filename]

The find Command#

Locate Files or Directories

Search 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 Output

Pipe the output of one command to another.

find . -name "file-0*" > output.txt
cat output.txt
Create Shortcuts

Create symbolic links to files.

ln -s [filename] [symlinkname]

Remove with:

rm [symlinkname]

File Compression#

Manage Archives

Create and extract tarballs with tar.

CommandDescription
tar czvf [dirname].tar.gz [dirname]Create tarball
tar tzvf [dirname]View tarball contents
tar xzvf [dirname].tar.gzExtract tarball

The history Command#

Command History

View and execute past commands.

history
!100

Run the 100th command in the history.

Common Terminal Commands
https://banije.vercel.app/posts/commonterminalcommands/
Author
ibra-kdbra
Published at
2022-09-20