Basic Commands I

Basic Commands I

This section describes Linux Command mostly used for beginners. 

  1. pwd— When you first open the terminal, you are in the home directory of your user. To know which directory you are in, you can use the “pwd” It gives us the absolute path, which means the path that starts from the root. The root is the base of the Linux file system. It is denoted by a forward slash( / ). The user directory is usually something like “/home/username”.

2. ls: Use the “ls” command to know what files are in the directory you are in. You can see all the hidden files by using the command “ls -a”.

    • ls -d */command to list only directories
    • ls * command to list the contents of the directory with it’s subdirectories:
    • ls -R command to list all files and directories with their corresponding subdirectories down to the last file
    • ls -a command to list files or directories including hidden files or directories.
    • ls -t command to list files or directories and sort by last modified date in descending order (biggest to smallest).
    • Type the ls > output.txt command to print the output of the preceding command into an output.txt file. We can use any arguments.
    • ls -l shows file or directory, size, modified date and time, file or folder name and owner of the file, and its permission.

3. cd— Use the “cd” command to go to a directory. For example, if you are in the home folder, and you want to go to the downloads folder, then you can type in “cd Downloads”. Remember, this command is case sensitive, and you have to type in the name of the folder exactly as it is. But there is a problem with these commands. Imagine you have a folder named “Raspberry Pi”. In this case, when you type in “cd Raspberry Pi”, the shell will take the second argument of the command as a different one, so you will get an error saying that the directory does not exist. Here, you can use a backward slash. That is, you can use “cd Raspberry\ Pi” in this case. Spaces are denoted like this: If you just type “cd” and press enter, it takes you to the home directory. To go back from a folder to the folder before that, you can type “cd ..” . The two dots represent back.

    • To navigate into the root directory, use “cd /”
    • To navigate to your home directory, use “cd”or “cd ~”
    • To navigate up one directory level, use “cd ..”
    • To navigate to the previous directory (or back), use “cd -“
    • To navigate through multiple levels of directory at once, specify the full directory path that you want to go to. For example, use, “cd /var/www”to go directly to the /www subdirectory of /var/. As another example, “cd ~/Desktop” will move you to the Desktop subdirectory inside your home directory.

Leave Comment

Your email address will not be published.