Basic Linux Commands

Basic Linux Commands

1) mkdir - Create a new directory

# The 'mkdir' command is used to create a new directory.
# Example usage:
mkdir new_directory

2) cd - Change the current directory

# The 'cd' command is used to change the current directory.
# Example usage:
cd new_directory

3) cp - Copy files and directories

# The 'cp' command is used to copy files and directories.
# Example usage:
cp source_file destination_file
#Options:
# -r for recursive
# -v for verbose
# -f for forcefully

4) mv - Move or rename files and directories

# The 'mv' command is used to move or rename files and directories.
# Example usage:
mv old_name new_name
#Options:
# -r for recursive
# -v for verbose
# -f for forcefully

5) rm - Remove files and directories

# The 'rm' command is used to remove files and directories.
# Example usage:
rm file_to_delete
#Options:
# -r for recursive
# -v for verbose
# -f for forcefully

6) rmdir - Remove empty directories

# The 'rmdir' command is used to remove empty directories.
# Example usage:
 rmdir empty_directory

7) touch - Create an empty file or update the timestamp of an existing file

# The 'touch' command is used to create an empty file or update the timestamp of an existing file.
# Example usage:
 touch new_file

8) cat - Display the contents of a file

# The 'cat' command is used to display the contents of a file.
# Example usage:
cat file_to_read

9) grep - Search for a pattern in a file or a group of files.

grep <options> <search pattern> <files>

#Options:
#The "grep" command has several options to modify its search behavior
#The "-i" option ignores case during search
#The "-r" or "-R" options search recursively through subdirectories
#The "-v" option inverts the match, displaying everything except the pattern
#The "-l" option lists only files that match the pattern
#The "-L" option lists only files that don't match the pattern
#The "-n" option prefixes each line of output with the line numberr

10) chmod - Change the permissions of a file or directory. You can use it to set read, write, and execute permissions for different users.

chmod <permission> <file/directory name>

#Set permission with numeric value
# 7 - Read, write, and execute permissions for the owner
# 6 - Read and write permissions for the owner
# 5 - Read and execute permissions for the owner
# 4 - Read permission for the owner
# 3 - Write and execute permissions for the owner
# 2 - Write permission for the owner
# 1 - Execute permission for the owner
# 0 - No permissions for the owner

11) chown - Change the owner of the file or directory.

chown <username> <file/directory name>

12) sudo - Execute a command with administrative privileges. It's often used to perform tasks that require root access.

sudo <command> # Run a command with administrative privileges

13) man - Display the manual page for a command. It provides detailed documentation and usage instructions for various commands.

man <command> # Display the manual page for a command

14) history - Show a list of previously executed commands.

history # Show a list of previously executed commands

15) wget - Download files from the internet using the command line. These are just a few basic Linux commands to get you started.

wget <URL> # Download files from the internet

16) top - display the top process running in the system

top # Display the top processes running in the system

17) useradd - create a new user account

useradd <username> # Create a new user account

18) passwd - create user account password

passwd <username> # Set or change a user account password

19) userdel - delete user account

userdel <username> # Delete a user account

20) groupadd - add Group account

groupadd <groupname> # Add a new group account

21) groupdel - delete group account

groupdel <groupname> # Delete a group account

22) find - find command used to search and locate lists of files and directories based on conditions applied

find <directory> -name <permission>

find <directory> -perm <permission>

find <directory> -user <user>

find <directory> -size -10Mjavascript:void(0);

23) locate - search a file by file name in the database, whereas the find command searches in the file system

locate <file_name>

24) awk - searches files for text containing a pattern

awk '{action}' your_file_name.txt

#search for text that has a specific pattern
awk '/regex pattern/{action}' your_file_name.txt

25) wc - used for the count and line numbers

#count number of lines
wc -l <directory>  
#count number of words
wc -w <directory>

26) head - head command is used to display top line of the file

head <directory>

head -n count <directory>
# n -> sused to specify no of lines to bes displayed

27) tail - tail command is used to display the bottom line of the file

tail<directory>

tail -n count <directory
# n -> sused to specify no of lines to bes displayed

28) tar - tar is used to compress size or drive backup

tar -<options> <files>

#Options:
# c - for create
# x - for extract
# v - for verbose
# f - for forcefully
# t - for test
# z - for gzip
# j - for bz2
# J - for xz
# C - for specific destination

29) vim - vim editor used for editing a file

vim filename.txt

30) date - display the current date and time

date
Wed Sep 22 14:30:42 UTC 2021

31) cal - display the current month's calendar

$ cal
   September 2021   
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30

32) echo - used to print text

echo "Hello, World!"