Get Started With Linux Cli

charancharan
8 min read

"Command Line Interface" (CLI) is a type of user interface that allows users to interact with a computer program or application by typing text commands in a terminal or console.

The computer doesn't under English it only understands's and 1's. It's very difficult to read or write . so , that why there is a special program called shell in operating systems . which is take a command and use the kernal execute the program .

Lets Starts Commands

  • First "man " command :

"man " is command when we use, it gives us the set of manual instructions how to use terminal and commands .

To use the man command follow the instructions

1.First open the terminal

2.Enter the command

man

mkdir :

The "mkdir" command is used to create a new directory (folder) in the current working directory. To use the command, you can open the terminal and type "mkdir" followed by the name of the directory you want to create.

  1.  mkdir file_name
    

Change directory (cd)

The "cd" command is used to change the current working directory in the terminal or console. To use the command, you can open the terminal and type "cd" followed by the name of the directory you want to navigate to.

cd file_name

cd .. command is used to navigate to the parent directory of the current working directory. It moves one level up in the directory tree. cd ~ command is used to navigate to the home directory of the current user. It takes you to the directory where you start each time you open the terminal.

"mv" command

The "mv" command is used to move or rename files and directories in the terminal or console. To use the command, you can open the terminal and type "mv" followed by the current name of the file/directory and the new name or path where you want to move it.

mv current_file_name new_file_name
mv current/path new/path

"cp" command

The "cp" command is used to copy files and directories in the terminal or console. If you want to copy a directory and its contents, you can use the "-r" or "-R" flag to enable recursive copying. For example, you can type "cp -r" followed by the name of the directory you want to copy and the path where you want to copy it to. - The "ls" command is used to list the files and directories in the current working directory in the terminal or console. You can use different flags to customize the output, such as "-l" for a detailed list, "-a" to show hidden files, and "-h" to display sizes in a human-readable format. For example, you can type "ls -l" to list the files with detailed information.

cp cuurent/filepath new/filepath

"pwd" command (present working directory)

The "pwd" command is used to print the current working directory in the terminal or console. It shows the full path of the directory you are currently in. You can type "pwd" in the terminal to see the path.

pwd

"rm " command (remove)

The "rm" command is used to remove files and directories in the terminal or console. You can use the "-r" or "-R" flag to enable recursive removal of directories and their contents. However, be careful when using this command as it permanently deletes the files/directories and there is no way to recover them.

//to remove file
rm file_name
//to remove directory
rm -r

"chmod" command (change mode)

The change mode is used to change the permissions of the files

d - is called directory

r - is called read , and also assigned number 4

w- is called write, and also assigned number 2

x- is called execute , and also assigned number 1

chmod 764 file_name
  • In the above command 7 is for owner it means he have the permissions to read, write and execute .

  • 6 is for group it means he have the permissions to read and write .

  • 1 it for the users it means he have the permissions to just read.

  • If you want to give all permissions to every one you could 777 and all like that

chown command(change owner command)

the chown command used to change the owner and group

chown user:group file_name

user means its the new owner we assigning to

group means its the new group we assigning to

sudo command (SuperUser do)

it is a command we use it update,install and remove , with the help of apt(Advanced Package Tool))

example:

//to install
sudo apt install fileName/package
//to update
sudo apt update filename/package
//to delete
sudo apt remove filename/package

touch command

touch is used to create the files

touch file_name

cat command

cat is used to display the content in the file

cat file_name

less command

less is used to display the less content in the file

less file_name

more command

more is used to display more content in the file

more file_name

tail command

tail is used to display of the last lines of the file

tail -n 5 file_name

"-n" means number of lines to print

rsync command

rsync is used to sync the files one location to another

rsync -rv curretn/location/filename destination/location/

Here are some common options used with rsync:

  • -a, --archive: Archive mode, preserves permissions, ownership, timestamps, and more.

  • -v, --verbose: Increase verbosity, providing more details during the synchronization process.

  • -r, --recursive: Recursively sync directories and their contents.

  • -z, --compress: Compress file data during the transfer, reducing network usage.

  • -n, --dry-run: Perform a trial run without making any changes, useful for testing.

  • -P, --partial --progress: Shows progress during transfer, and keeps partially transferred files.

--delete: Delete extraneous files from the destination directory.

grep command

  • grep stands for "Global Regular Expression Print".

  • It's used to search for specific patterns or expressions within files.

      grep [OPTIONS] PATTERN [FILE...]
    

    options

  • -i igonres the case distinctions.

  • -o Prints only the matching parts

find command

  • find is used to search for files and directories in a directory hierarchy.

  • It can perform actions on the files it finds.

      find [PATH] [OPTIONS] [ACTIONS]
    
  • Example: find /home/user -name "*.txt" searches for all .txt files in the /home/user directory.

Common options:

  • -name: Search for files by name.

  • -type: Search for files of a specific type (e.g., -type f for regular files, -type d for directories).

  • -exec: Execute a command on the files found.

sort command

  • The sort command is used to sort the lines of text files in alphabetical or numerical order.

  • Basic syntax: sort [OPTIONS] [FILE]

  • Example: sort myfile.txt

Common options:

  • -r: Reverse the sorting order.

  • -n: Sort numerically.

  • -u: Output only unique lines.

date command

display the time and date

tree command

tree command gives you the structure of the folder

tree folder_name

wc command

wc means word count

  • -l: Count lines.

  • -w: Count words.

-c: Count characters

wc -l file_name
  1. ps:

    • Displays information about currently running processes.

    • Commonly used options:

      • ps aux: Shows detailed information about all processes running on the system.
  2. top:

    • Interactive process viewer command used to display dynamic real-time information about system processes and resource usage.

    • Provides a comprehensive overview of CPU, memory, and other system resources.

  3. df:

    • Reports file system disk space usage.

    • Useful for checking disk space on mounted filesystems.

    • Commonly used options:

      • df -h: Displays disk space usage in a human-readable format.
  4. uname:

    • Prints system information, including the system name, kernel version, and machine architecture.

    • Commonly used options:

      • uname -a: Displays all available system information.
  5. free:

    • Displays the amount of free and used memory in the system, including physical and swap memory.

    • Useful for monitoring memory usage and availability.

  6. lspci:

    • Lists all PCI devices connected to the system.

    • Provides detailed information about PCI devices such as their vendor, device ID, and bus type.

  7. kill:

    • Sends signals to processes, allowing you to control their behavior or terminate them.

    • Commonly used options:

      • kill -9 <PID>: Sends the SIGKILL signal to terminate a process forcefully.
  1. ping:

    • Sends ICMP echo request packets to a specified network host to test network connectivity and measure round-trip time.

    • Commonly used options:

      • ping -c <count> <hostname>: Sends a specified number of ICMP echo requests to the hostname.
  2. ifconfig:

    • Displays network interface configuration information, including IP addresses, MAC addresses, and network settings.

    • Commonly used options:

      • ifconfig <interface>: Displays information for a specific network interface.
  3. ssh:

    • Secure Shell command used to securely connect to a remote system over a network.

    • Allows for secure remote login, remote command execution, and file transfer.

  1. xargs:

    • Reads items from standard input and executes a command with those items as arguments.

    • Useful for building and executing commands dynamically.

  2. printenv:

    • Prints the values of environment variables.

    • Useful for displaying the current environment configuration.

  3. nano:

    • Simple text editor for Unix-like operating systems.

    • Easy-to-use and beginner-friendly compared to other text editors like Vim or Emacs.

  4. awk:

    • Powerful text processing tool for extracting and manipulating text data.

    • Allows for pattern scanning and processing.

  5. sed:

    • Stream editor for filtering and transforming text.

    • Useful for performing text transformations, substitutions, and deletions.

Pipe Operator |:

  • Connects the output of one command to the input of another command.

  • Allows for chaining multiple commands together to perform complex operations.

  • Enables the creation of powerful one-liners for data manipulation and processing.

0
Subscribe to my newsletter

Read articles from charan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

charan
charan