Mastering Linux - Essential Command Line Basics
Mastering Linux - Essential Command Line Basics
• ls:- The ls command in Linux is used to list files and directories within
a specified directory. It's one of the most commonly used commands
and has several options to customize its output. Here are some of the
basic and commonly used options with ls:
• ls: Simply typing ls without any options will list files and directories in the
current directory.
• ls -l: Lists files and directories in long format, providing detailed
information such as permissions, ownership, size, and timestamps.
• ls -a: Displays all files, including hidden files (those starting with a dot).
• ls -h: Prints file sizes in a human-readable format.
• ls -t: Sorts files by modification time, showing the newest files first.
• ls -r: Lists files in reverse order.
• ls -R: Recursively list subdirectories.
Cd:- The cd command in Linux is used to change directories
within the file system. It allows you to navigate through different
directories and move to a specific directory.
Here's how it works:
cat filename: Displays the content of the specified file on the terminal.
•cat file1 file2: Concatenates and displays the content of multiple files.
•cat > filename: Allows you to create a new file and add content to it from the
terminal.
•cat >> filename: Appends content to an existing file.
Additional options :
-n (or --number): Numbers all the output lines. For example, cat -n file numbers
all lines in the file.
•-b (or --number-nonblank): Numbers non-blank lines. Blank lines won't be
numbered.
•-s (or --squeeze-blank): Squeezes consecutive blank lines into one. It doesn't
remove all blank lines but condenses multiple consecutive blank lines into a
single blank line.
•-E (or --show-ends): Displays a $ character at the end of each line to indicate
the line endings.
•-T (or --show-tabs): Displays ^I where tabs are instead of just showing the tab
spacing.
•-v (or --show-nonprinting): Shows non-printing characters (like control
characters and special characters) in a visible way.
grep:- grep is a powerful command-line tool in Linux used for
searching text patterns within files or command output. It stands for
"Global Regular Expression Print." It allows users to search for specific
strings or patterns and print lines that match those patterns.