Basic Linux Command

Basic Linux Command

A Linux Command is a program that runs on a Command line interface(CLI).

Linux commands are case-sensitive.

  • cd - cd command is used to change the directory. It requires the directory name. For Example- Let’s say you’re in /home/username/Documents and want to go to the picture, a subdirectory of Documents. To do so, enter the following command:

    cd picture

    • cd ~[username] goes to another user’s home directory.

    • cd .. moves one directory up.

    • cd- moves to your previous directory.

  • ls - ls command is used to list files and directories. it shows the content of a current working directory. To see the other directory content we have to write ls/<Directory path>

    ls -a shows hidden files in addition to the visible ones.

  • cat - cat means concatenate. This cat command is one of the most frequently used Linux commands. it helps us to list, combine and write file content to standard output. cat file1.txt

    here is some way to write the cat command:

    • cat > file1.txt creates a new file.

    • cat file1.txt file2.txt > file3.txt merges file.txt and file2.txt and stores the output in file3.txt.

    • tac file1.txt displays content in reverse order

  • cp - cp command is used to copy the files or directories.

    To copy the content of a file to a new file in the same directory cp file1.txt file2.txt

    To copy an entire directory, we use cp -R<source directory><destination directory>

  • mv - mv command is used to move and rename the files or directories.

    For example- if we want to move file1.txt to a directory then the command is mv file1.txt(destination directory path>

    To rename the file1.txt to newfile.txt - mv file1.txt newfile.txt

  • mkdir - mkdir command is used to create one or multiple directories.

    For example- the command to create a directoy name as folder1 mkdir folder1

    if we want to create multiple directories then the command is mkdir folder1 folder2 folder3

  • touch - touch command is used to create one or multiple empty files.

    For example- to create one file touch file1 and to create multiple files touch file1 file2 file3

  • history - The history command is used to list previously executed commands.

  • hostname - with the help of the hostname command we know the system hostname.

  • useradd - useradd command is used to create a new user account.

  • userdel - we delete the created user with help of userdel command.

  • ping - ping command is used to check a network or server's reachability.

  • rm - rm command is used to files in a directory

    • rm -i prompts system confirmation before deleting a file.

    • rm -f allows the system to remove without a confirmation

  • pwd - pwd command is used to know the current working directory.

  • sudo - sudo command is used in Linux commands to perform any task with administrative privileges.

  • su - su command is used to switch the user. it allows us to run a program as a different user. this command runs through root privilege.