Some important commands in Linux

·

5 min read

what is / in linux ?

In Linux, / (forward slash) is the root directory of the file system. All other directories and files are located under the root directory, and it serves as the starting point of the file system hierarchy. The / is used to separate the directories in the path of a file or directory.

For example, if a file named file.txt is located in the home directory of the user john, the full path to the file would be /home/john/file.txt, where / represents the root directory, home represents a subdirectory under root, john represents a subdirectory under the home directory, and file.txt represents the file located under john directory.

What is the command to check your present working directory?

"pwd" is the command used to check the present working directory.

What is the command to list all the files or directories including hidden files?

ls -a is the command to list all the files or directories including hidden files. The -a option shows all files including hidden files in the output.

What is the command to list the files and directories in a long list format with extra information?

The ls -l command is used to list files and directories in a long format, which includes information such as permissions, owner, group, size, and modification date/time.

What is the command to list all including hidden files and directory?

The ls -l command is used to list files and directories in a long format, which includes information such as permissions, owner, group, size, and modification date/time.

What is the command to list all the files having .sh extension?

The command to list all the files having .sh extension in the current directory is ls *.sh

What is the command to delete files in Linux?

To delete files in Linux, you can use the rm command. Here are the basic usage examples:

  1. To delete a single file:

     rm filename
    
  2. To delete multiple files:

     rm file1 file2 file3
    
  3. To delete all files in a directory:

     rm *
    

    Note: This will delete all files in the directory, including hidden files. Be careful when using this command.

  4. To delete all files with a specific extension:

     rm *.extension
    

    For example, to delete all .txt files in the current directory:

     rm *.txt
    
  5. To delete a directory and its contents:

     rm -r directory_name
    

    Note: The -r flag stands for "recursive", which means that all subdirectories and files within the directory will also be deleted. Be careful when using this command.

What is the command to list the files and directories with index numbers inodes?

what are index numbers inodes

In Linux file systems, an inode (short for "index node") is a data structure that stores all the information about a file except for its name and actual data. This information includes file size, ownership, permissions, timestamps, and the location of the data on the disk. Each file in the file system has a unique inode number, which is used by the system to reference the file.

In essence, the inode acts as a pointer to the file's data on the disk. When a file is deleted, the inode is removed from the file system, and the data associated with it is marked as free space and can be overwritten. This is why it is possible to recover deleted files using specialized software, as long as the data has not been overwritten by new data.

The command ls -i is used to display the index number (inode number) of each file in a directory. The inode number is a unique identifier for a file or directory in the file system. It is used by the file system to locate and manage files and directories.

What is the command to list only directories?

ls -d */ is the command to list only directories.

The */ tells the ls command to only show directories, because only directories have a trailing slash (/) in their name. The -d option tells ls to list only the directories themselves, and not their contents.

ls -ld */ will list only directories in the current directory.

  • ls is the command for listing files and directories.

  • -ld are two separate flags. -l tells the command to use a long listing format, and -d tells it to only list directories and not their contents.

  • */ is the parameter that tells the command to list only directories. The * is a wildcard character that matches any string of characters, and the / specifies that the matched items must be directories.

What is the command to change the directory to the home directory?

cd ~ or cd is the command used to change the current working directory to a different directory.

cd

cd ~

What is the command to go to the last working directory?

The cd - command takes you to the previous working directory. It is a convenient way to toggle between two directories.

What is the command used to go one step back?

The cd .. command is used to navigate one step back in the directory structure.

What is the command used to go two steps back?

The command cd ../.. takes you up two directories from your current directory.

What is the command used to create folder?

The mkdir command is used to create a new directory.

What is the command used to create hidden folder?

The command "mkdir .foldername" will create a hidden folder in the current working directory.

The command "mkdir .hiddenfolder" will create a hidden folder named ".hiddenfolder" in the current working directory.

What is the command used to create multiple directories?

The command mkdir A B C D will create four directories named A, B, C, and D in the current working directory.

What is the command used to create a directory in a specific location?

To create a directory in a specific location, you can use the mkdir command followed by the absolute or relative path of the directory you want to create.

eg: mkdir /home/mukesh/alphabets/x/y/z

What is the command to create a nested directory A/B/C/D/E?

mkdir is the command used to create directories and the -p option ensures that any missing parent directories are also created.

mkdir -p A/B/C/D/E