3 Must Know File and Directory Commands in Linux Ubuntu

Must-know file and directory commands in Linux Ubuntu. These file management commands in Linux can help upu to find home directory in Linux. Use these commands to view the current working directory; home directory in Linux.

Home Directory

A home directory, also called a login directory, is the directory on Unix-like operating systems that serves as the repository for a user’s personal files, directories and programs. It is also the directory that a user is first in after logging into the system. A home directory is created automatically for every ordinary user in the directory called /home. The root directory, which is designated by a forward slash ( / ), is the directory that contains all other directories and their subdirectories as well as all files on the system.

The name of a user’s home directory is by default identical to that of the user.

  • NOTE: There are several easy ways for a user to return to its home directory regardless of its current directory (i.e., the directory in which it is currently working in). The simplest of these is to use the cd (i.e., change directory) command without any options or arguments (i.e., input files), i.e., by merely typing the following and then pressing the ENTER key.
  • NOTE: By default, when you open terminal, you are placed in the home directory. The current directory is represented by a single dot.

1. CD Command

The cd command, which stands for “change directory”, changes the shell’s current working directory. It is a builtin command, which means that it is executed directly by your shell, instead of launching an external program. cd is among the commands you will use most often on the command line. To change into the root directory, making it your working directory, use the command “cd /” in terminal. When a directory name is provided, cd changes the current directory to it.

2. PWD Command

‘pwd’ prints the name of the current directory. The command has a simpler format “pwd [OPTION]…” The command accepts various options.

  • ‘-L’ or ‘–logical’ – If the contents of the environment variable ‘PWD’ provide an absolute name of the current directory with no ‘.’ or ‘..’ components, but possibly with symbolic links, then output those contents. Otherwise, fall back to default ‘-P’ handling.
  • ‘-P’ or ‘–physical’ – Print a fully resolved name for the current directory. That is, all components of the printed name will be actual directory names—none will be symbolic links.

If ‘-L’ and ‘-P’ are both given, the last one takes precedence.

3. LS Command

These options determine which files ‘ls’ lists information for. By default, ‘ls’ lists files and the contents of any directories on the command line, except that in directories it ignores files whose names start with ‘.’.

  • Using ‘-d’ or ‘–directory’ option with ls command shows just the names of directories, as with other types of files, rather than listing their contents. Do not follow symbolic links listed on the command line unless the ‘–dereference-command-line’ (‘-H’), ‘–dereference’ (‘-L’), or ‘–dereference-command-line-symlink-to-dir’ options are specified.
  • Using ‘-a’ option with ls shows all files. Showing all files means including the hidden files. Make a note that when a file name on a Linux file system starts with a dot, it is considered a hidden file and it doesn’t show up in regular file listings.

The ‘ls’ program lists information about files (of any type, including directories). Options and file arguments can be intermixed arbitrarily, as usual.

By default ‘ls’ lists the contents of directories, not recursively, and omitting files with names beginning with ‘.’. For other non-option arguments, by default ‘ls’ lists just the file name. If no argument is specified, ‘ls’ operates on the current directory, acting as if it had been invoked with a single argument of ‘.’.

By default, the output is sorted alphabetically.

3 Must Know File and Directory Commands in Linux Ubuntu originally posted on Source Digit – Latest Technology, Gadgets & Gizmos.