SOHAIL
ASGHER
Linux File Navigation
Linux File Navigation
This session (L6 S4) explained Linux file navigation as it
refers to moving through directories in a Linux system.
A Linux system is organized in a hierarchical structure of
directories.
Navigating this structure lets users access, edit, and
organize files.
SOHAIL
ASGHER
Linux File Navigation
Why is it Important?
Accessing Files: To open or work on files, you need to know the
correct directory.
Organizing Files: Proper navigation helps keep files organized.
System Maintenance: Administrators use it for software
installation and system updates.
Efficient Workflow: Quick and accurate navigation improves
productivity.
SOHAIL
ASGHER
Linux File Navigation
File Operations Commands
Following are some main commands for File
Operations:
1) Print Working Directory (pwd)
2) Manual (man)
3) Make Directory (mkdir)
4) Create an empty file (touch)
5) Move/Rename files (mv)
6) Copy files or directories (cp)
7) Remove/Delete files (rm)
1) Print Working Directory (pwd)
Syntax of Command:
pwd
Example:
pwd outputs the path of the directory you are currently in.
SOHAIL
ASGHER
Linux File Navigation
File Operations Commands
2) Manual (man)
Syntax of Command:
man [command]
Example:
man ls shows the manual for the ls command.
3) Make Directory (mkdir)
Syntax of Command:
mkdir [directory_name]
Example:
mkdir new_folder creates a directory named "new_folder."
4) Create an empty file (touch)
Syntax of Command:
touch [file_name]
Example:
touch file.txt creates an empty file named "file.txt."
SOHAIL
ASGHER
Linux File Navigation
File Operations Commands
5) Move/Rename files (mv)
Syntax of Command:
mv [source] [destination]
Example:
mv old_name.txt new_name.txt renames "old_name.txt".
6) Copy files or directories (cp)
Syntax of Command:
cp [source] [destination]
Example:
cp file.txt backup.txt copies "file.txt" to "backup.txt."
7) Remove/Delete files (rm)
Syntax of Command:
rm [options] [file/directory]
Example:
rm file.txt deletes "file.txt."
SOHAIL
ASGHER
Linux File Navigation
Content View Commands
Following are some main commands for Content View
Commands:
1) Concatenate file content (cat)
2) View file content navigation (less)
3) View file content (more)
4) Display last lines of file (tail)
1) Concatenate file content (cat)
Syntax of Command:
cat [file]
Example:
cat file.txt displays the content of "file.txt."
2) View file content navigation (less)
Syntax of Command:
less [file]
Example:
less file.txt opens "file.txt" for viewing.
SOHAIL
ASGHER
Linux File Navigation
Content View Commands
3) View file content (more)
Syntax of Command:
more [file]
Example:
more file.txt displays "file.txt" one screen at a time.
4) Display last lines of file (tail)
Syntax of Command:
tail [options] [file]
Example:
tail -n 5 file.txt shows the last 5 lines of "file.txt."
SOHAIL
ASGHER
Linux File Navigation
Navigation Linux File System
Following are some main commands for Navigation
Linux File System:
1) Stay in the current directory (cd)
2) Change Directory (cd)
3)Move Up into directory (cd ..)
4) Back to the previous directory (cd -)
5) Back to root directory (cd /)
6) Move to absolute path (cd/path/to/directory)
1) Stay in the current directory (cd)
Syntax of Command:
cd
Example:
Simply typing cd takes you to the home directory.
2) Change Directory (cd)
Syntax of Command:
cd [directory_path]
Example:
cd /home/user/documents changes the current directory
SOHAIL
ASGHER
Linux File Navigation
Navigation Linux File System
3)Move Up into directory (cd ..)
Syntax of Command:
cd ..
Example:
cd .. would take you from /home/user/ to /user.
4) Back to the previous directory (cd -)
Syntax of Command:
cd -
Example:
Iuse cd -, it will take you back to "/home/user."
5) Back to root directory (cd /)
Syntax of Command:
cd /
Example:
cd / moves you to the root directory of the file system.
6) Move to absolute path (cd/path/to/directory)
Syntax of Command:
cd /path/to/directory
Example:
cd /usr/local/bin takes you directly to the directory.
SOHAIL
ASGHER
Linux File Navigation
File Management & Permissions
Following are some main commands for File
Management & Permissions:
1) List directory contents (ls)
2) List with detailed information (ls -l)
3) List all files (ls -a)
4) List non-printable characters files (ls -b)
5) List files with numeric IDs (ls -n)
6) Change file permissions (chmod)
7) Change file owner and group (chown)
8) Convert and copy files (dd)
9) Display last lines of file (tail)
10) Search for files (find)
11) Securely copy files (scp)
12) Show disk space (df)
SOHAIL
ASGHER
Linux File Navigation
File Management & Permissions
1) List directory contents (ls)
Syntax of Command:
ls [options] [file]
Example:
ls -l lists directory contents with detailed information
(permissions, ownership, size).
2) List with detailed information (ls -l)
Syntax of Command:
ls -l [file]
Example:
ls -l /home/user/ shows detailed information about files in the
home directory.
3) List all files (ls -a)
Syntax of Command:
ls -a [file]
Example:
ls -a /home/user/ lists all files, including hidden ones, in the
specified directory.
SOHAIL
ASGHER
Linux File Navigation
File Management & Permissions
4) List non-printable characters files (ls -b)
Syntax of Command:
ls -b [file]
Example:
ls -b /home/user/ shows non-printable characters in filenames
in the directory.
Command Full Name:
5) List files with numeric IDs (ls -n)
Syntax of Command:
ls -n [file]
Example:
ls -n /home/user/ lists files and shows numeric IDs for users and
groups.
6) Change file permissions (chmod)
Syntax of Command:
chmod [options] [permissions] [file]
Example:
chmod 755 file.txt changes the permissions of file.txt to be
readable, but only writable by the owner.
SOHAIL
ASGHER
Linux File Navigation
File Management & Permissions
7) Change file owner and group (chown)
Syntax of Command:
chown [options] [owner][:group] [file]
Example:
chown user:group file.txt changes the owner of file.txt to "user"
and the group to "group".
8) Convert and copy files (dd)
Syntax of Command:
dd [options] if=[input file] of=[output file]
Example:
dd if=/dev/sda of=/dev/sdb clones the contents of one disk to
another.
9) Display last lines of file (tail)
Syntax of Command:
tail [options] [file]
Example:
tail -n 10 file.txt displays the last 10 lines of file.txt.
SOHAIL
ASGHER
Linux File Navigation
File Management & Permissions
10) Search for files (find)
Syntax of Command:
find [path] [options] [expression]
Example:
find /home -name "*.txt" searches for files in home directory.
11) Securely copy files (scp)
Syntax of Command:
scp [options] [source] [destination]
Example:
scp file.txt user@remote:/path/to/destination/ copies file.txt.
12) Show disk space (df)
Syntax of Command:
df [options] [file]
Example:
df -h shows disk usage in human-readable format.
SOHAIL
ASGHER
Linux File Navigation
Process Management
Following are some main commands for Process
Management:
1) Interactive process viewer (htop)
2) Report a snapshot (ps)
3) Terminate processes by ID (kill)
4) Display the command history (history)
5) Display free memory (free)
1) Interactive process viewer (htop)
Syntax of Command:
htop
Example:
htop launches an interactive process viewer.
2) Report a snapshot (ps)
Syntax of Command:
ps [options]
Example:
ps aux shows all running processes.
SOHAIL
ASGHER
Linux File Navigation
Process Management
3) Terminate processes by ID (kill)
Syntax of Command:
kill [options] [pid]
Example:
kill -9 12345 forcibly terminates the process with ID 12345.
4) Display the command history (history)
Syntax of Command:
history [options]
Example:
history displays a list of previously executed commands.
5) Display free memory (free)
Syntax of Command:
free [options]
Example:
free -h shows memory usage in human-readable format.
SOHAIL
ASGHER
Linux File Navigation
User & Group Navigation
Following are some main commands for User & Group
Navigation:
1) Add a new user (sudo useradd)
2) Set a user password (sudo passwd)
3) Delete a user (sudo userdel)
d) Show user ID (id)
e) Show group ID (id -g)
1) Add a new user (sudo useradd)
Syntax of Command:
sudo useradd [username]
Example:
sudo useradd john adds a new user named "john".
2) Set a user password (sudo passwd)
Syntax of Command:
sudo passwd [username]
Example:
sudo passwd john sets the password for the user "john".
SOHAIL
ASGHER
Linux File Navigation
User & Group Navigation
3) Delete a user (sudo userdel)
Syntax of Command:
sudo userdel [username]
Example:
sudo userdel john deletes the user "john".
4) Show user ID (id)
Syntax of Command:
id [options] [username]
Example:
id john shows the user ID for the user "john".
5) Show group ID (id -g)
Syntax of Command:
id -g [groupname]
Example:
id -g admin shows the group ID of the "admin" group.
SOHAIL
ASGHER
Linux File Navigation
Text Manipulation
Following are some main commands for Text
Manipulation:
1) Sort text lines in reverse (sort -r)
2) Sort lines of text (sort -f)
3) Remove file line sections (cut)
d) Compare files line (diff)
1) Sort text lines in reverse (sort -r)
Syntax of Command:
sort -r [file]
Example:
sort -r names.txt sorts the lines in names.txt in reverse order.
2) Sort lines of text (sort -f)
Syntax of Command:
sort -f [file]
Example:
sort -f names.txt sorts the lines in names.txt ignoring case.
SOHAIL
ASGHER
Linux File Navigation
Text Manipulation
3) Remove file line sections (cut)
Syntax of Command:
cut [options] [file]
Example:
cut -d ',' -f 1 data.csv extracts the first field of each line in
data.csv.
4) Compare files line (diff)
Syntax of Command:
diff [options] [file1] [file2]
Example:
diff file1.txt file2.txt compares file1.txt and file2.txt line by line.
System Information
Following are some main commands for System
Information:
a) Display the OS name (uname -o)
b) Show the machine hardware (uname -m)
c) Show the kernel release (uname -r)
d) Display CPU architecture info (lscpu)
SOHAIL
ASGHER
Linux File Navigation
System Information
1) Display the OS name (uname -o)
Syntax of Command:
uname -o
Example:
uname -o displays the operating system name.
2) Show the machine hardware (uname -m)
Syntax of Command:
uname -m
Example:
uname -m displays the hardware name.
3) Show the kernel release (uname -r)
Syntax of Command:
uname -r
Example:
uname -r displays the kernel release.
4) Display CPU architecture info (lscpu)
Syntax of Command:
lscpu
Example:
lscpu shows detailed CPU architecture information.
SOHAIL
ASGHER
Linux File Navigation
Package Management
Following are some main commands for Package
Management:
1) Install or remove software packages (apt-get)
2) Uninstall a specific package (sudo apt-get remove)
1) Install or remove software packages (apt-get)
Syntax of Command:
apt-get [options]
Example:
sudo apt-get install package_name installs a package.
2) Uninstall a specific package (sudo apt-get remove)
Syntax of Command:
sudo apt-get remove [package_name]
Example:
sudo apt-get remove firefox uninstalls Firefox.
SOHAIL
ASGHER
Linux File Navigation
Network Configuration & Monitoring
Following are some main commands for Network
Configuration & Monitoring:
1) Display network interfaces (ifconfig)
2) Show routing, devices (ip)
3) Query domain name servers (nslookup)
4) Show network connection (netstat)
5) Connect to remote systems (telnet)
6) Transfer data from or to a server (curl)
1) Display network interfaces (ifconfig)
Syntax of Command:
ifconfig [interface]
Example:
ifconfig eth0 shows the configuration of network interface eth0.
2) Show routing, devices (ip)
Syntax of Command:
ip [options]
Example:
ip addr shows IP addresses assigned to all network interfaces.
SOHAIL
ASGHER
Linux File Navigation
Network Configuration & Monitoring
3) Query domain name servers (nslookup)
Syntax of Command:
nslookup [hostname]
Example:
nslookup example.com queries the DNS server for the IP address
4) Show network connection (netstat)
Syntax of Command:
netstat [options]
Example:
netstat -an shows all network connections and listening ports.
5) Connect to remote systems (telnet)
Syntax of Command:
telnet [hostname] [port]
Example:
telnet example.com 80 connects to example.com on port 80.
6) Transfer data from or to a server (curl)
Syntax of Command:
curl [options] [url]
Example:
curl http://example.com retrieves data from example.com.
SOHAIL
ASGHER
Linux File Navigation
Text Searching
Following are some main commands for Text
Searching:
1) Case-insensitive search (grep -i)
2) Show line in search results (grep -n)
3) Show lines not matching pattern (grep -v)
4) Count occurrences of the pattern (grep -c)
1) Case-insensitive search (grep -i)
Syntax of Command:
grep -i [pattern] [file]
Example:
grep -i "hello" file.txt searches for the word "hello" ignoring case.
2) Show line in search results (grep -n)
Syntax of Command:
grep -n [pattern] [file]
Example:
grep -n "hello" file.txt searches for "hello" & shows line numbers.
SOHAIL
ASGHER
Linux File Navigation
Text Searching
3) Show lines not matching pattern (grep -v)
Syntax of Command:
grep -v [pattern] [file]
Example:
grep -v "hello" file.txt shows all lines that do not contain "hello."
4) Count occurrences of the pattern (grep -c)
Syntax of Command:
grep -c [pattern] [file]
Example:
grep -c "hello" file.txt counts how many times "hello" appears.
System Monitoring
Following are some main commands for System
Monitoring:
1) List open files (lsof)
2) List open files for a user (lsof -u)
SOHAIL
ASGHER
Linux File Navigation
System Monitoring
1) List open files (lsof)
Syntax of Command:
lsof [options]
Example:
lsof lists all open files.
2) List open files for a user (lsof -u)
Syntax of Command:
lsof -u [username]
Example:
lsof -u john lists all open files for the user "john".
Miscellaneous
Following are some main Miscellaneous commands:
1) List running Docker containers (docker ps)
2) List Docker images (docker images)
3) Build a Docker image (docker build)
4) Run a command in a new container (docker run)
5) Stop a running container (docker stop)
6) Create containers (docker-compose up)
7) Stop containers (docker-compose down)
SOHAIL
ASGHER
Linux File Navigation
Miscellaneous
1) List running Docker containers (docker ps)
Syntax of Command:
docker ps
Example:
docker ps lists all running Docker containers.
2) List Docker images (docker images)
Syntax of Command:
docker images
Example:
docker images lists all Docker images on the system.
3) Build a Docker image (docker build)
Syntax of Command:
docker build [options] [path]
Example:
docker build -t myimage . builds a Docker image from the
Dockerfile in the current directory.
4) Run a command in a new container (docker run)
Syntax of Command:
docker run [options] [image]
Example:
docker run -it myimage /bin/bash starts a new container.
SOHAIL
ASGHER
Linux File Navigation
Miscellaneous
5) Stop a running container (docker stop)
Syntax of Command:
docker stop [container_id]
Example:
docker stop 12345 stops the container with ID 12345.
6) Create containers (docker-compose up)
Syntax of Command:
docker-compose up [options]
Example:
docker-compose up starts all containers in docker-compose.yml
7) Stop containers (docker-compose down)
Syntax of Command:
docker-compose down [options]
Example:
docker-compose down stops and removes all containers.
SOHAIL
ASGHER
Linux File Navigation
Screen
Following are some main commands for Screen:
1) Reattach to a screen session (screen -r)
2) Detach from the screen (Ctrl+A+D)
1) Reattach to a screen session (screen -r)
Syntax of Command:
screen -r [screen_name]
Example:
screen -r myscreen reattaches to the screen session.
2) Detach from the screen (Ctrl+A+D)
Syntax of Command:
Ctrl+A+D
Example:
Ctrl+A+D detaches current screen session without stopping it.
PM2
PM2 is a process manager for Node.js applications that can
manage apps in production environments.