Skip to content

Instantly share code, notes, and snippets.

@ravikyada
Created July 18, 2024 07:49
Show Gist options
  • Save ravikyada/01e50b728d7eb5135fb52768b20a4bf8 to your computer and use it in GitHub Desktop.
Save ravikyada/01e50b728d7eb5135fb52768b20a4bf8 to your computer and use it in GitHub Desktop.

Common Most Useful Terminal Commands

User Information

Show the current logged-in user.

whoami

Date and Time

Display the current date and time.

date

File System Navigation

Command Description
pwd Print working directory
ls List directory contents
ls -a List all contents including hidden files
ls -l List contents with detailed information
cd Change to home directory
cd [dirname] Change to specific directory
cd .. Change to parent directory
find [dirtosearch] -name [filename] Find a file or directory

Opening Files or Folders

Open files or directories in GUI.

  • Mac: open [dirname]
  • Windows: start [dirname]
  • Linux: xdg-open [dirname]

Modifying Files & Directories

Command Description
mkdir [dirname] Make directory
touch [filename] Create file
rm [filename] Remove file
rm -r [dirname] Remove directory
cp [filename] [dirname] Copy file
mv [filename] [dirname] Move file
mv [filename] [filename] Rename file or directory

Output Redirection

Create a new file with output.

> [filename]

Concatenate Files

View, create, or append files.

cat [filename]
cat > [filename]
cat >> [filename]

Viewing Files

View file contents with scrolling.

less [filename]

Exit with q.

Display Text

Display messages or create/write files.

echo "Hello World"
echo "Hello World" > [filename]
echo "Hello World" >> [filename]

Text Editor

Edit files with Nano.

nano [filename]

Exit with Ctrl + X, then Y to save or N to discard.

Head and Tail

Display the beginning or end of files.

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

Search Text

Search for patterns in files.

grep [searchterm] [filename]

Find Files

Locate files and directories.

find [dirname] -name [filename]
find . -empty
find . -name "file-*" -delete

Piping

Redirect output to another command or file.

find . -name "file-0*" > output.txt

Symlinks

Create shortcuts to files or directories.

ln -s [filename] [symlinkname]
rm [symlinkname]

For Windows:

mklink [symlinkname] [filename]

File Compression

Compress or extract files with tar.

Command Description
tar czvf [dirname].tar.gz [dirname] Create tarball
tar tzvf [dirname] See contents of tarball
tar xzvf [dirname].tar.gz Extract tarball

Networking Commands

Command Description
ifconfig Display network configuration
ip addr show Display IP addresses and network interfaces
ping [hostname] Check connectivity to a host
traceroute [hostname] Trace the route packets take to a network host
nslookup [hostname] Query the DNS for information about a domain
dig [domain] Detailed DNS query
netstat Network statistics
curl [url] Transfer data from or to a server
wget [url] Download files from the web

System Monitoring

Command Description
top Display active processes
htop Interactive process viewer
ps Display information about active processes
df Report file system disk space usage
du Estimate file space usage
free Display memory usage
uname -a Display system information

Disk Usage

Command Description
df -h Show disk usage in human-readable format
du -sh [dirname] Show disk usage for a directory
du -shl * Show disk usage for all items in a directory

Package Management (Linux)

Command Description
apt-get update Update package lists (Debian/Ubuntu)
apt-get upgrade Upgrade installed packages (Debian/Ubuntu)
yum update Update packages (RedHat/CentOS)
yum upgrade Upgrade packages (RedHat/CentOS)

System Information

Command Description
uname -r Show kernel version
lsb_release -a Show Linux distribution information
hostnamectl Query and change the system hostname

Permissions

Command Description
chmod [options] [filename] Change file mode (permissions)
chown [owner]:[group] [file] Change file owner and group
sudo [command] Execute a command as another user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment