Common Linux Commands
The Linux command line is a text interface to your computer. Often referred to as the shell, terminal, console, prompt or various other names, it can give the appearance of being complex and confusing to use. Yet the ability to copy and paste commands from a website, combined with the power and flexibility the command line offers, means that using it may be essential when trying to follow instructions online, including many on this very website!
File and Directory Management
ls
- List directory contents1 2 3
ls ls -l ls -a
cd
- Change directory1 2 3
cd /path/to/directory cd .. cd ~
pwd
- Print working directory1
pwd
mkdir
- Create a new directory1 2
mkdir directory_name mkdir -p /path/to/directory
rmdir
- Remove an empty directory1
rmdir directory_name
rm
- Remove files or directories1 2
rm file_name rm -r directory_name
cp
- Copy files or directories1 2
cp source_file destination_file cp -r source_directory destination_directory
mv
- Move or rename files or directories1 2
mv source_file destination_file mv old_directory_name new_directory_name
touch
- Create an empty file or update the timestamp of an existing file1
touch file_name
find
- Search for files in a directory hierarchy1
find /path/to/search -name "file_name"
File Viewing and Editing
cat
- Concatenate and display file content1
cat file_name
less
- View file content one screen at a time1
less file_name
more
- View file content one screen at a time1
more file_name
head
- Display the first few lines of a file1 2
head file_name head -n 10 file_name
tail
- Display the last few lines of a file1 2
tail file_name tail -n 10 file_name
nano
- Simple text editor in the terminal1
nano file_name
vi
orvim
- Advanced text editor in the terminal1 2
vi file_name vim file_name
System Information and Management
top
- Display real-time system information1
top
ps
- Display information about active processes1 2
ps ps aux
df
- Display disk space usage1 2
df df -h
du
- Estimate file space usage1 2 3
du du -h du -sh directory_name
free
- Display memory usage1 2
free free -h
uname
- Display system information1 2
uname uname -a
Networking
ping
- Send ICMP ECHO_REQUEST to network hosts1
ping host_name_or_ip
ifconfig
- Configure a network interface (deprecated, useip
instead)1
ifconfig
ip
- Show/manipulate routing, devices, policy routing, and tunnels1 2
ip address ip link
netstat
- Network statistics (deprecated, usess
instead)1
netstat
ss
- Utility to investigate sockets1 2
ss ss -tuln
scp
- Securely copy files between hosts1
scp source_file user@remote_host:/path/to/destination
wget
- Non-interactive network downloader1
wget url
lsof
- List open files, useful to check ports1
lsof -i :port_number
kill
- Terminate a process by PID1 2
kill pid kill -9 pid
Package Management
apt-get
- APT package handling utility (Debian/Ubuntu)1 2 3
sudo apt-get update sudo apt-get install package_name sudo apt-get remove package_name
yum
- Package manager (Red Hat/CentOS)1 2 3
sudo yum update sudo yum install package_name sudo yum remove package_name
dnf
- Package manager (Fedora)1 2 3
sudo dnf update sudo dnf install package_name sudo dnf remove package_name
Permissions and Ownership
chmod
- Change file modes or Access Control Lists1 2
chmod 755 file_name chmod -R 755 directory_name
chown
- Change file owner and group1 2
chown user_name:group_name file_name chown -R user_name:group_name directory_name
Archiving and Compression
tar
- Store, list, or extract files in an archive1 2 3 4
tar -cvf archive_name.tar directory_name tar -xvf archive_name.tar tar -czvf archive_name.tar.gz directory_name tar -xzvf archive_name.tar.gz
zip
- Package and compress files1 2
zip archive_name.zip file1 file2 zip -r archive_name.zip directory_name
unzip
- Extract compressed files from a ZIP archive1
unzip archive_name.zip
Miscellaneous
echo
- Display a line of text1
echo "Hello, World!"
date
- Display or set the system date and time1 2
date date -s "2024-07-31 12:34:56"
whoami
- Print the current user name1
whoami
man
- Display the manual for a command1
man command_name
history
- Display the command history1
history
This post is licensed under
CC BY 4.0
by the author.