To secure a data job in 2024, mastering Unix isn’t just a nice-to-have—it’s a necessity. 🎯
I am sure you already know the importance of this versatile operating system, right?
For those on their learning journey, I have a complete list of essential Unix commands for beginners at your fingertips that can make the process significantly smoother.
Instead of searching multiple sources, you can now access a comprehensive, organized command list all in one place, ensuring you have the tools you need exactly when you need them.
If you’re committed to mastering Unix and searching for a quick command reference, your search ends here.
List of Unix Commands
ls command
used to list the files and directories.
ls
ls -l
ls -a
ls -i
ls -R
Option | Usage |
-a | to display all files including hidden files(beginning with .) |
-l | Long listing the file i.e. with attributes like permissions, size etc. |
-i | to list directory contents along with inode number |
-R | to list directory contents along with the inode number |
pwd command
used to display the present working directory.
pwd
cd command
used to change the directory.
- cd directory_name (This command takes you directly to the folder you need to work in)
cd home/user/dir1
- cd .. (This command navigates you back to the previous directory, allowing you to backtrack through your directory structure quickly.)
cd ..
man command
used to view the manual for a specific command
man command_name
//example
man ls
mkdir command
used to create new directories
mkdir directory_name
//example
mkdir dir1
rmdir command
used to remove the directory
rmdir directory_name
//example
rmdir dir1
cal command
used to display calendar
cal (Displaying the current month)
cal -3 (Displaying the previous, current and next month)
cal -y (Displaying whole year)
cal -m (Starting the week from Monday)
cal -ym (Whole year calendar starting from Monday)
Date command
used to display dates
date
date -d 10/07/2024
date +"%a %d %b %y"
who command
used to display who is logged in
who
who -m
-m | Displaying all Information of Logged-In Users |
-a | Displaying all Information of All Logged-In Users |
-q | Displaying Login Names and Terminal Line Numbers |
-H | Displaying Output with Headings |
-b | Displaying Time of Last System Boot |
echo command
used to display a line of text
echo "You are learning unix"
output: You are learning unix
echo -e "This is unix \n 2nd line"
output: this is unix
2nd line
echo "23+56" | bc
output: 79
cat command
used to concatenate, display or append the files
- Write into the file
cat>file1
this is first line
this is second line
- Append the file
cat >> file1
this is third line added
- View the file
cat file1
- Concatenate a file
cat file1 file2 > combined_file
Pipelining
with the help of the pipe, the output of the command can be given as input to the next command.
-l | to print the line count |
-w | to print the word counts |
-c | to print the byte count |
-m | to print the character count |
cat access.log | wc
head command
used to display first ‘n’ lines from the file.
head -n filename
//example
head -2 file1
or,
cat filename | head -n
//example
cat file1 | head -2
tail command
used to display the last ‘n’ lines from the file.
tail -n filename
//example
tail -2 file1
or,
cat filename | tail -n
//example
cat file1 | tail -2
cut command
used to extract columns from each line of the file
-b | Bytes, select only these bytes. |
-c | Characters, select only these characters. |
-d | Delimiter, select only the basis of the delimiter provided |
-f | Select only specified fields |
//example1
cut -d '/" -f2 access.log
//example2
cut -d "-" -f1,2 access.log | cut -d ' ' -f 1,3
uniq command
to display the unique values
cut -d ' ' -f1,3 access.log | uniq -c
sort command
used to sort the elements in ascending or descending order
-t | to specify the delimiter |
-k | to specify starting and ending columns for sorting |
-r | to sort in reverse order |
-n | to some kind of numerical data |
-u | to some numerical data |
-c | to remove the duplicate line |
//example1
cut -d ' ' -f1,3 access.log | uniq -c | sort
//example2
cut -d ' ' -f1,3 access.log | uniq -c | sort -r
tr command
translating character
-d | deleting the character |
-s | compressing multiple consecutive character |
-c | complementing values of expression |
//converts loweracase to uppercase
tr '[a-z]' '[A-Z]' < logs.txt
tr -d '[]' < logs.txt
grep command
used for searching and manipulating text patterns within files.
grep 'Inverter' access.log | tail -5
//for case insensitive search add -i
grep -i 'inverter' access.log
grep '^12' access.log
grep '8[1-9]' marks
pattern matching
* | to match zero or more occurrences of the previous character |
[pqrs] | character class- to match a single character p,q,r or s |
[^pqrs] | to match a single char which is not p,q,r or s |
^pattern | to match the pattern at the beginning of the line |
pattern$ | to match the pattern as a whole line |
^$ | to match lines containing nothing |
+ | match one or more occurrences of previous char |
? | match zero or one occurrence of the previous char |
pattern1|pattern2 | to match pattern1 or pattern2 |
(Fin|Eng)land | to match Finland or England |
cp command
used to copy files and directories
cp [options] source destination
-i or interactive | Prompts before overwriting. |
-r or -R | Recursively copies directories. |
-u or update | Copies only when the source file is newer than the destination file or when the destination file is missing. |
-v or verbose | Shows files being copied. |
-a or archives | Preserves attributes and copies directories recursively. |
-b or backup | take backup of destination |
- copy a file
cp file1.txt file2.txt
- copying multiple files into directory
cp file1.txt file2.txt file3.txt /path/to/destination/
mv command
to move or rename files. Like cp command, it will moved to the destination location but the source copy is deleted
- -b or –backup
- -i or –interactive
- -u or update
- -n or -no-clobber
mv file1.txt /backup_dir/file2.txt
Access Permissions
Types of Permissions
- Read (r): Allows viewing the contents of the file or directory.
- Write (w): Allows modifying the contents of the file or directory.
- Execute (x): Allows executing the file or accessing the directory.
Permission Categories
Permissions are assigned to three categories of users:
- Owner (u): The user who owns the file or directory.
- Group (g): The group that owns the file or directory.
- Others (o): All other users.
Viewing the permission
ls -l filename
//output
-rwxr-xr--
rwx | ||
0 | 000 | — |
1 | 001 | –x |
2 | 010 | -w- |
3 | 011 | .wx |
4 | 100 | r– |
5 | 101 | r-x |
6 | 110 | rw- |
7 | 111 | rwx |
Changing the permission
to change the permission “chmod” is used
-R | to change the file and directory permissions recursively |
–reference | to use the permission of the first argument as a reference to set permission of remaining arguments |
chmod -R 755 /home/user1
chmod -R ugo+x /home/user1/app_dir
Working with an editor
In VI editor, there is 3 mode:
- command mode
When you enter the VI editor default you will be in command mode.
- insert mode(interpreted as raw text)
To insert text into the file, you need to switch to ‘VI’ insert mode.
you can type text into the file or use arrow keys to navigate
(n)h | move n position left |
(n)j | move n lines down |
(n)k | move n lines up |
(n)l | move n position right |
$ | move to end of current line |
Operations with insert mode
i | insert data before cursor |
I | insert data at start of current line |
a | insert data after cursor |
A | insert data at end of current line |
o | starts a new line after cursor |
O | starts a new line before cursor |
- escape mode(keys are interpreted for saving/exit purpose)
After insert mode, if you press ESC you will enter into command mode. On typing a ‘:’ you can enter into escape mode andgve command to save and quit the editor.
To save and quit the VI editor
:w | save changes |
:wq | save changes and exit |
:q | exit from editor |
:q! | exit from editor and discard changes made |
Closing Words
These essential Unix commands are where you begin your journey with the command line.
Regular practice will boost your confidence in using them effectively.
For detailed Unix commands, you can reference the websites like geeksforgeeks.
I hope you found this helpful!
Feel free to leave any questions or suggestions in the comments below.
Enjoy learning and exploring!✨
Leave a Reply