LINUX COMMANDS
clear clear screen
cd copy directory
mkdir make a new directory
rmdir remove a directory
touch filename.extension make a new file
pwd current location
| pipe operator (like an adapter)
more uses for better organization
; termination of the code
nano filename
vim filename
cp copy
cp -r
PID’s
ps aux display all running process
ps aux | grep process_name display all running process with
specific name
top
echo $! display last command executed
pidof process_name shows the PID of a running process
by its name
kill PID to kill command
kill -9 PID Forcefully kill the process
Word Count Commands
wc option filename.ext
Lines (-l)
Words (-w)
Characters (-m)
Bytes (-c)
Listing inside Folder
ls option
-l # Long format (with permissions, size, date)
-a # Show hidden files
-lh # Human-readable file sizes
-la # Combine long format and hidden files
-R # Recursive listing (including subdirectories)
To display calendar
{sudo apt install ncal}
cal option
-y # for full year
monthNumber year # Specific date
ex cal 3 2023 #calendar for march 2023
To display in who commands
who option
All details (-a)
Last boot time (-b)
Current runlevel (-r)
Terminal writable status (-T)
Show column headers (-H)
Idle time of users (-u)
To display ln commands(links)
Hard links - exact copy
Soft links - copy which points to original copy (shortcut)
ln file link_name Create a hard link to a file.
ln -s file link_name Create a symbolic (soft) link to
ln -s /path/to/file /path/to/link Create a symbolic link in a
different location.
ln -s directory link_name Create a symbolic link to a
directory.
ln -sf file link_name Force create a symbolic link
(overwrite if exists).
ln -v file link_name Show details of the link creation
(verbose mode).
ln -i file link_name Ask for confirmation before
overwriting an existing link.
1. Viewing Processes
● ps aux – Show all running processes.
● ps -ef – Another way to display running processes.
● top – Display real-time process information.
● htop – Interactive process viewer (needs to be installed).
● pgrep <process_name> – Find process IDs by name.
2. Finding Specific Processes
● pidof <process_name> – Find the PID of a running process.
● ps aux | grep <process_name> – Find a process manually.
3. Killing Processes
● kill <PID> – Kill a process by PID.
● kill -9 <PID> – Forcefully kill a process.
● pkill <process_name> – Kill a process by name.
● killall <process_name> – Kill all instances of a process.
4. Background & Foreground Processes
● & – Run a process in the background (e.g., command &).
● jobs – List background processes.
● fg <job_id> – Bring a background process to the foreground.
● bg <job_id> – Resume a stopped background process.
5. Process Prioritization
● nice -n <priority> <command> – Start a process with a
specific priority.
● renice <priority> -p <PID> – Change priority of an existing
process.
6. Monitoring Processes
● watch <command> – Run a command periodically.
● strace -p <PID> – Trace system calls made by a process.
● lsof -p <PID> – List open files by a process.
7. Stopping & Resuming Processes
● Ctrl + Z – Suspend a foreground process.
● kill -STOP <PID> – Pause a process.
● kill -CONT <PID> – Resume a paused process.
8. Process Resource Usage
● vmstat – Show system performance stats.
● iostat – Display CPU and I/O usage.
● free -m – Check memory usage.
● uptime – Show system load averages.
1. Check File Size
● ls -lh <file> – Show file size in a human-readable format.
● stat <file> – Display detailed file information, including size.
● du -h <file> – Show the disk usage of a specific file.
2. Check Directory Size
● du -sh <directory> – Display total size of a directory.
● du -ah <directory> – Show the size of all files and
subdirectories.
● du -ch <directory> – Display sizes of all files and
subdirectories, with a total at the end.
3. Find Largest Files
● ls -lhS – List files in the current directory sorted by size.
● find /path -type f -exec du -h {} + | sort -rh |
head -n 10 – Find the 10 largest files in a directory.
Vim commands
q quit
w save
SHELL SCRIPT COMMANDS
chmod +x filename.ext to make shell script file executable
echo “ ” to print
ls
ls [option] [file/directory]
Options
known as a long format that displays detailed information about files
-l
and directories.
-a Represent all files Include hidden files and directories in the listing.
Sort files and directories by their last modification time, displaying
-t
the most recently modified ones first.
known as reverse order which is used to reverse the default order of
-r
listing.
-
Sort files and directories by their sizes, listing the largest ones first.
S
-
List files and directories recursively, including subdirectories.
R
known as inode which displays the index number (inode) of each file
-i
and directory.
- known as group which displays the group ownership of files and
g directories instead of the owner.
-
Print file sizes in human-readable format (e.g., 1K, 234M, 2G).
h
-
List directories themselves, rather than their contents.
d