0% found this document useful (0 votes)
22 views2 pages

Essential Linux OS Commands Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Essential Linux OS Commands Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

OS Commands

1- PWD: show Current Directory (Present working directory)


2- LS: List all files and directories in your current directory
3- LS -al: List detailed information about files
4- Cd /directoryname (ex: cd /bin): change directory to another
5- cd: move to home
6- cd /: move to root
7- cat > filename: create a new file and add the content then press ctrl+d to return to command line
8- cat filename: show content of the file

9- cat file1 file2 > newfile: merge 2 files in one file


10- rm filename: remove a file
11- MV: Renaming the file or directory
12- mkdir directoryname: Create a directory
13- rmdir directoryname: remove a directory
14- Man commandname (Man history): gives information about this command
15- History: shows all the commands that you have used.
16- pr -x filename (pr -3 file1): divides the data into 3 columns.
17- pr -h “Header” filename: Making header for file.
18- pr -n filename: denotes all the lines in the file with numbers
19- Chmod (764) filename: changing the permissions of file by ABSOLUTE(NUMERIC)
METHOD 20- Chmod (g+w) filename: changing the permissions of file by SYMBOLIC METHOD
21- ls -al > listing: redirect the output

22- echo “welcome” >> filename: add more content to an existing file
23- cat Filename | less: Pipe is a command in Linux that lets you use two or more
commands 24- cat filename | grep (word): search a particular information in the file
25- cat filename | grep -v (word or letter): Shows all the lines that do
not match the searched string

26- cat filename | grep -i (word or letter): Match both (upper and
lower) case

27- cat filename | grep -c (word or letter): Displays only the count
of matching lines

28- cat filename | grep -n (word or letter): Shows the matching line and
its number

29- Sort filename: sorting the contents of a file alphabetically


30- Sort -r filename: reverse sorting
31- Sort -n filename: sort numerically
32- cat filename | grep -i a | sort -r: filtered output of the first command is given to the
next 33- Variablename=vale: creating a new variable

34- echo $VARIABLENAME: determine value of a variable


35- unset variablename: remove a Variable from the system

Common questions

Powered by AI

'sort -n filename' provides numerical sorting, which is advantageous over 'sort filename' for numerical data by sorting based on number values rather than lexicographical order. This is preferred in scenarios like sorting a list of numbers in a data file containing sales figures or rankings, where numerical order matters for meaningful analysis or reporting .

The 'LS -al' command extends the functionality of the basic 'LS' command by providing a detailed listing of files and directories, including hidden files, with additional metadata such as permissions, links, owner, group, size, and modification date. This comprehensive view is invaluable for managing files and understanding the attributes and structure of directories .

The command 'cat file1 file2 > newfile' merges the contents of two files into a new file, creating or overwriting 'newfile'. In contrast, 'echo “welcome” >> filename' appends new content to an existing file without overwriting. This distinction is crucial for determining whether data is preserved or replaced during file operations .

The 'cd /directoryname' command changes the current working directory to a specified directory path, significantly impacting workflow efficiency in a multi-directory project environment by allowing quick navigation between directories. This enhances productivity by reducing time spent manually browsing directory structures, thus aiding in seamless project file management and execution .

The command 'cat filename | grep -c (word)' counts the number of lines in a file that contain a specific word. This is particularly beneficial in scenarios where quantifying occurrences of certain terms or phrases is needed, such as analyzing log files for error messages or tracking the frequency of specific data entries, enabling efficient data processing and pattern recognition .

A user might prefer symbolic methods like 'chmod (g+w) filename' for their intuitive representation of permission changes, explicitly stating which permissions are modified. This command adds write permissions for the group, clarifying the action without interpreting numeric codes, thus reducing errors in permission settings, especially for users who manage complex access rights .

The 'man commandname' command displays the manual or help file for a specified command, enhancing a user's ability to utilize shell commands effectively by providing comprehensive information on command syntax, options, usage examples, and descriptions. This access to detailed documentation empowers users to understand and leverage command capabilities fully .

Pipes, like in 'cat Filename | less', allow the output of one command to serve as the input for another, enabling command chaining in a shell environment. This facilitates complex data processing workflows by allowing multiple commands to be executed sequentially without intermediate files, thereby streamlining operations and reducing manual intervention .

The command 'chmod (764) filename' changes the file permissions using the absolute (numeric) method, where the digits represent different levels of access for the owner, group, and others. The number '7' grants the owner full read, write, and execute permissions. '6' grants the group read and write permissions without execute. '4' allows others to read the file only. These permissions are crucial for controlling access and maintaining security .

The 'PWD' command stands for 'print working directory'. Its primary function is to display the current working directory in the file system, which is critical for navigation because it helps users understand their current location within the directory structure, ensuring they execute further commands in the correct context .

You might also like