Unix Basic Commands
🎯 FILE CREATION USING CAT
To create a new file and add content to it, you can use the cat command with the output redirection operator (>).
[system]$ cat > samp.txt
Explanation
The cat command is used to concatenate and display the content of files. When used with the output redirection operator (>), it creates a new file or overwrites an existing one with the content entered from the keyboard.
In the example, the user is prompted to enter the content for the file samp.txt. After pressing the Enter key, the content is saved to the file.
🎯 DISPLAY FILE CONTENTS
To display the contents of a file, you can use the cat command followed by the filename.
[system]$ cat samp.txt
Explanation
The cat command, when used without redirection, displays the content of the specified file (samp.txt in this case) in the terminal.
🎯 LISTING FILES IN A DIRECTORY
To list the files and directories in the current working directory, use the ls command.
[system]$ ls
Explanation
The ls command lists the files and directories in the current working directory.
In the example, several filenames and directories are listed.
🎯 APPENDING CONTENTS TO A FILE
To add content to the end of a file, use the cat command with the append operator (>>).
[system]$ cat >> samp.txt
Explanation
The cat command with the append operator (>>) is used to add content to the end of the file samp.txt.
After executing the command, the user is prompted to enter additional content, which will be appended to the file when they press Ctrl+D.
🎯 WORD COUNT
To count the number of lines, words, and characters in a file, use the wc command.
[system]$ wc sam.txt
or
[system]$ wc -w sam.txt
Explanation
The wc command is used to count the number of lines, words, and characters in a file.
The first command (wc sam.txt) displays the number of lines, words, and characters in the file sam.txt.
The second command (wc -w sam.txt) displays only the number of words in the file sam.txt.
🎯 CREATING EMPTY DIRECTORY
To create an empty directory, use the mkdir command followed by the directory name.
[system]$ mkdir empty
Explanation
The mkdir command is used to create a new directory with the name empty in the current working directory.
🎯 REMOVING EMPTY DIRECTORY
To remove an empty directory, use the rm command followed by the directory name.
[system]$ rm empty
Explanation
The rm command is used to remove a file or directory. In this case, it is used to remove the empty directory named empty.
🎯 VIEWING FILE PERMISSIONS
To view file permissions along with other details, use the ls -l command.
[system]$ ls -l
Explanation
The ls -l command displays detailed information about the files and directories in the current working directory, including permissions, owner, group, size, modification date, and filename.
🎯 VIEW ABSOLUTE PATH
To view the absolute path of the current working directory, use the pwd command.
[system]$ pwd
Explanation
The pwd command stands for "print working directory" and displays the absolute path of the current directory.
🎯 CREATING DIRECTORY
To create a new directory, use the mkdir command followed by the directory name.
[system]$ mkdir new_dir
Explanation
The mkdir command creates a new directory with the name new_dir in the current working directory.
🎯 ECHO COMMAND
To print a message or a value to the terminal, use the echo command.
[system]$ echo "sat"
Explanation
The echo command is used to print the string "sat" to the terminal.
🎯 CAL COMMAND
To display the calendar for the current month, use the cal command.
[system]$ cal
Explanation
The cal command displays the calendar for the current month, with the current day highlighted.
🎯 DATE COMMAND
To display the current date and time, use the date command.
[system]$ date
Explanation
The date command shows the current date and time in the format "Day Month Date Time Timezone Year."
🎯 CALENDAR FOR A SPECIFIC YEAR
To display the calendar for a specific year, use the cal command followed by the year.
[system]$ cal 2011
Explanation
The cal 2011 command displays the calendar for the year 2011, showing each month with its corresponding days.
🎯 USERS CURRENTLY LOGGED IN
To view a list of users currently logged in, use the who command.
[system]$ who
Explanation
The who command displays a list of users currently logged into the system, along with their login information.
🎯 CHANGE DIRECTORY
To change the current working directory, use the cd command followed by the desired directory name.
[system]$ cd solai
Explanation
The cd command is used to change the current working directory to solai.
🎯 COPY CONTENTS FROM ONE FILE TO ANOTHER
To copy the contents of one file to another, use the cp command followed by the source and destination filenames.
[system]$ cp sam.txt sol.txt
Explanation
The cp command is used to copy the content of the file sam.txt to the file sol.txt.
🎯 MOVE FILE TO ANOTHER DIRECTORY
To move a file from one location to another, use the mv command followed by the source and destination filenames or directories.
[system]$ mv sol.txt sol/
Explanation
The mv command moves the file sol.txt to the directory sol.
🎯 RENAME FILE
To rename a file, use the mv command followed by the current filename and the new filename.
[system]$ mv sol.txt sat.txt
Explanation
The mv command renames the file sol.txt to sat.txt.
In summary, this blog post now contains detailed explanations for each Unix command, making it easier for readers to understand their functionalities and how to use them effectively.