File System Navigation
pwd - Print Working Directory
Shows the current directory path
$ pwd
/home/username
ls - List Directory Contents
Lists files and directories
$ ls -la
total 64
drwxr-xr-x 5 user user 4096 Dec 15 10:30 .
drwxr-xr-x 3 root root 4096 Dec 14 09:15 ..
-rw-r--r-- 1 user user 220 Dec 14 09:15 .bash_logout
cd - Change Directory
Moves between directories
$ cd /var/log
$ pwd
/var/log
mkdir - Make Directory
Creates new directories
$ mkdir new_folder
$ ls
new_folder
rmdir - Remove Directory
Removes empty directories
$ rmdir empty_folder
File Operations
touch - Create Empty File
Creates new empty files
$ touch newfile.txt
$ ls -l
-rw-r--r-- 1 user user 0 Dec 15 10:35 newfile.txt
cp - Copy Files/Directories
Copies files and directories
$ cp file.txt file_backup.txt
$ ls
file.txt file_backup.txt
mv - Move/Rename Files
Moves or renames files
$ mv oldname.txt newname.txt
$ mv file.txt /tmp/
rm - Remove Files
Deletes files and directories
$ rm unwanted_file.txt
$ rm -r directory_name
cat - Concatenate Files
Displays file content
$ cat file.txt
Hello, this is file content.
Line 2 of the file.
head - Show Beginning of File
Displays first lines of a file
$ head -5 file.txt
Line 1
Line 2
Line 3
Line 4
Line 5
tail - Show End of File
Displays last lines of a file
$ tail -3 file.txt
Line 8
Line 9
Line 10
File Permissions and Ownership
chmod - Change File Permissions
Modifies file permissions
$ chmod 755 script.sh
$ chmod +x executable_file
chown - Change File Owner
Changes file ownership
$ chown user:group file.txt
chgrp - Change File Group
Changes file group ownership
$ chgrp developers file.txt
Searching and Finding
find - Search for Files
Searches for files and directories
$ find /home -name "*.txt"
/home/user/file1.txt
/home/user/documents/note.txt
grep - Search Text Patterns
Searches for patterns in files
$ grep "error" logfile.txt
ERROR: Connection failed
Error: File not found
locate - Find Files Quickly
Uses database to quickly find files
$ locate httpd.conf
/etc/httpd/conf/httpd.conf
which - Locate Command
Shows full path of commands
$ which python
/usr/bin/python
whereis - Locate Binary, Source, and Manual
Locates binary, source, and manual pages
$ whereis python
python: /usr/bin/python /usr/lib/python2.7 /usr/include/python2.7
System Information
uname - System Information
Shows system information
$ uname -a
Linux server1 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
whoami - Current User
Displays current username
$ whoami
username
id - User Identity
Shows user and group information
$ id
uid=1000(user) gid=1000(user) groups=1000(user),4(adm),24(cdrom),27(sudo)
date - System Date and Time
Shows or sets system date/time
$ date
Mon Dec 15 10:45:30 UTC 2023
uptime - System Uptime
Shows how long system has been running
$ uptime
10:50:30 up 15 days, 3:20, 2 users, load average: 0.05, 0.10, 0.15
Process Management
ps - Process Status
Shows current processes
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 169316 13004 ? Ss Dec14 0:02 /sbin/init
top - Process Monitor
Dynamic real-time process viewer
$ top
kill - Terminate Processes
Sends signals to processes
$ kill 1234
$ kill -9 1234
pkill - Kill Processes by Name
Kills processes by name
$ pkill firefox
jobs - List Background Jobs
Shows background jobs
$ jobs
[1]- Running sleep 1000 &
[2]+ Running nano file.txt &
Networking
ping - Network Connectivity Test
Tests network connectivity
$ ping google.com
PING google.com (172.217.16.206) 56(84) bytes of data.
64 bytes from muc11s01-in-f14.1e100.net (172.217.16.206): icmp_seq=1 ttl=117 time=15.4 ms
ifconfig - Network Interface Configuration
Configures network interfaces (older)
$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
wget - Web Downloader
Downloads files from the web
$ wget https://example.com/file.zip
Resolving example.com (example.com)... 93.184.216.34
Connecting to example.com (example.com)|93.184.216.34|:443... connected.
curl - URL Transfer Tool
Transfers data from or to a server
$ curl -O https://example.com/file.txt
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 312k 100 312k 0 0 1034k 0 --:--:-- --:--:-- --:--:-- 1034k