Basic Shell Commands
Basic Shell Commands
• ls -l
• -l: Long format displays files and
listing. directories with detailed
• -a: Include information.
List files and hidden files • ls -a
ls
directories. hidden ones shows all files and
• -h: Human- directories, including
readable file • ls -lh
sizes. displays file sizes in a
human-readable format.
• cd /path/to/directory
changes the current
cd Change directory.
directory to the specified
path.
• pwd
Print current
pwd displays the current
working directory.
working directory.
• mkdir my_directory
Create a new
mkdir creates a new directory
directory.
named “my_directory”.
• rm file.txt
deletes the file named
“file.txt”.
• -r: Remove
• rm -r my_directory
directories
deletes the directory
Remove files and recursively.
rm “my_directory” and its
directories. • -f: Force removal
contents.
without
• rm -f file.txt
confirmation.
forcefully deletes the file
“file.txt” without
confirmation.
• cp -r directory
destination
copies the directory
• -r: Copy “directory” and its contents
Copy files and
cp directories to the specified
directories.
recursively. destination.
• cp file.txt destination
copies the file “file.txt” to
the specified destination.
Basic Shell Commands
• mv file.txt new_name.txt
renames the file “file.txt” to
Move/rename files “new_name.txt”.
mv
and directories. • mv file.txt directory
moves the file “file.txt” to
the specified directory.
• cat file.txt
View the contents
cat displays the contents of
of a file.
the file “file.txt”.
• head file.txt
shows the first 10 lines of
• -n: Specify the
Display the first the file “file.txt”.
head number of lines
few lines of a file. • head -n 5 file.txt
to display.
displays the first 5 lines of
the file “file.txt”.
• tail file.txt
shows the last 10 lines of
• -n: Specify the
Display the last the file “file.txt”.
tail number of lines
few lines of a file. • tail -n 5 file.txt
to display.
displays the last 5 lines of
the file “file.txt”.
• ln -s source_file
• -s: Create link_name
Create links
ln symbolic (soft) creates a symbolic link
between files.
links. named “link_name”
pointing to “source_file”.
• find /path/to/search -
• -name: Search by
name “*.txt”
Search for files filename.
find searches for all files with
and directories. • -type: Search by
the extension “.txt” in the
file type.
specified directory.