The command line interface (CLI) is a powerful tool for interacting with your computer's operating system. It provides a way to execute various tasks efficiently and manage files and directories using commands. In this guide, we'll walk you through essential Linux commands that can make your CLI experience smooth and productive.
Navigation Commands:
cal: Display a calendar for the current month.
cd: Change the working directory.
cd /
: Switch to the root directory.cd ~
: Switch to the home directory.cd ..
: Navigate to the parent directory.
pwd: Show the current working directory.
ls: List files and directories.
ls -i
: Display inode numbers.ls -l
: List files with detailed information.ls -t
: List items based on creation time.ls -a
: Show hidden items.ls -r
: List items in reverse order.ls -R
: List all files including subfolders.
File and Directory Manipulation:
mkdir: Create a new directory.
mkdir my\ Cat
: Create a directory with spaces.mkdir "my cat is cute"
: Create a directory with spaces.
touch: Create an empty file or update timestamps.
rm: Delete files or directories.
rm -R
: Recursively delete non-empty folders.rm -i
: Prompt before removing a file.rm -f
: Forcefully delete without confirmation.rm -v
: Display deletion summary.
cp: Copy files or directories.
cp file*
: Copy files starting with "file".cp *.txt
: Copy files with ".txt" extension.cp [abc]* dir1
: Copy files starting with "a", "b", or "c" to "dir1".cp [!abc]* dir1
: Copy files not starting with "a", "b", or "c" to "dir1".cp [0-9]* dir1
: Copy files with numbers to "dir1".cp [[:upper:]]* dir1
: Copy files starting with a capital letter to "dir1".
mv: Move or rename files or directories.
ln: Create hard or soft (symbolic) links between files.
Text Editors and Viewing Commands:
nano: Edit file contents using the nano text editor.
cat: View the contents of a file.
head: Display the first lines of a file.
head -n 20 fileName
: Display the first 20 lines.
tail: Display the last lines of a file.
tail -n 20 fileName
: Display the last 20 lines.
w: Display file information such as lines, words, and longest line.
File: Determine the type of a file.
Keyboard Shortcuts:
Ctrl + A
: Move to the beginning of the line.Ctrl + D
: Delete the character at the cursor.Ctrl + E
: Move to the end of the line.Ctrl + K
: Delete all characters after the cursor.Ctrl + Y
: Undo deletion.Ctrl + L
: Clear the terminal.
Working with History:
history
: Display command history.history 100
: Show the last 100 commands.nano .bash_history
: Edit command history.history -c
: Clear command history.
Additional Tips:
man command
: Access the manual for a specific command.whatis command
: Display a brief description of a command.
Mastering the Linux command line can greatly enhance your productivity and control over your system. These essential commands empower you to navigate directories, manipulate files, view content, and perform a range of tasks with ease. Whether you're a beginner or an experienced user, this guide provides a solid foundation for effectively utilizing the command line interface. By integrating these commands into your workflow, you'll become a proficient command line user in no time.