Linux Fundamentals Part-1

Linux Fundamentals Part-1

All these below commands work on Linux, macOS, WSL, and anywhere you have a UNIX environment.

  1. sudo command

    sudo is one of the most popular basic Linux commands that lets you perform tasks that require administrative or root permissions.

    Syntax : sudo (command)

    Output :

  2. pwd command

    Get the full path of the current working directory. Simply entering pwd will return the full current path – a path of all the directories that starts with a forward slash (/). For example, /home/username.

    Syntax: pwd

    Output:

  3. cd command

    Navigate to the last directory you were working in.

    Syntax : cd -

    Output:

  4. ls command

    The ls command lists files and directories within a system. Running it without a flag or parameter will show the current working directory’s content.

    below are some examples with flags.

    ls -l

    List the files and directories in the current directory in long (table) format (It is recommended to use -l with ls for better readability).

    ls -ld dr-name

    List information about the directory dir-name instead of its contents.
    ls -a

    List all the files including the hidden ones (File names starting with a . are hidden files in Linux).

    ls -lt

    List the files sorted by last modified time with the most recently modified files showing at the top

    ls -lh

    List the file sizes in a human-readable format.

    ls -lR

    Shows all subdirectories recursively.

    tree

    Tree representation of the file system.

  5. cp command

    Use the cp command to copy files or directories and their content.

    Syntax: cp -p source destination

    Will copy the file from the source to the destination. -p stands for preservation. It preserves the original attributes of file while copying like file owner, timestamp, group, permissions etc.

Syntax: cp -R source_dir destination_dir

Will copy source directory to specified destination recursively.

  1. mkdir command

    Use the mkdir command to create one or multiple directories at once and set permissions for each of them.

    Syntax: mkdir dirctory_Name

    Create a directory dir-name.

    Syntax: mkdir -p dir-name/dir-name

    Create a directory hierarchy. Create parent directories as needed, if they don't exist. You can specify multiple directories.

  2. rmdir command

    To permanently delete an empty directory, use the rmdir command. Remember that the user running this command should have sudo privileges in the parent directory.

    Syntax: rmdir dir-name

    Only removes directory if its empty.

    Syntax: rmdir -p directory1/directory2

  3. touch command

    Create a file filename, if it doesn't exist, otherwise change the timestamp of the file to the current time.

    Synatx: touch filename

    output:

    -----------------------------------------------------------------------------------

Happy Learning😊

Thanks,

Vishal Ranmale