Categories
Design

How to use the cd command on linux

Unix is an open-source multi-tasking operating system which was developed in 1969 by a group of AT&T employees at Bell Labs. I am not going to discuss the whole history of Unix here and make this post boring. I am very big fan of open-source operating system Linux, which is evolved from Unix and its first kernel was developed by Linus Torvalds. Today Linux operating system is widely used in home desktop, laptops, web-hosting server’s and even in supercomputers.

Today latest mobile revolution operating system, Android also run on Linux kernel. Today, I am gonna discuss about some basic Linux command, which I use every day and are very helpful if you are Linux administrator.

How to use the cd command on linux

Everyday Basic Linux Commands with Examples

1. uname: This command is very useful in verifying the server name. When you type this command in your UNIX machine, it will print name, version and other details about the current machine and server.

Example: $ uname -a : This command will print the server or machine name along with server version.

2. df : This is a system information command which is used to show disk usage. This command is always used when a system administrator handles the Filesystem issue in Linux or SunOS servers or systems.

Example: $ df -h or df -k

The above command will show disk usage of all the mounted disk in human-readable forms like GB and MB. This command does not work on Solaris 8. For that, you will have to use K instead of h like #df -k

$ df -h / : This Will show root disk usage.
$ df -h /opt : Will show /opt disk usage.
$ df -h /var : Will show /var disk usage.

3. date: This is a very common UNIX command which is used to see the date of the system. If you are working on a different time zone, then this command is very helpful.

Example: $ date : Will display the current date of the system.

4. uptime: This command is used to show the current uptime of the machine. Suppose you have a server that is running from 120 days, and when you input this command, you will get output 120. This command can be used to know the last boot date of the system though there are other commands for this.

Example: $ uptime : This will show for how long system or server is up.

5. du: This command when entered will show directory space usage of that particular directory.

Example: $ du -sh . : This will show your current directory usage in GB or MB.

$ du -sh * : This command will show all the current usage of the directory and files present in a particular directory.

6. pwd: This command stands for Present Working Directory and show my present working directory in Linux and SUN operating system.

Example: $ pwd : /home/tech2blog

7. ls: This command is useful when you need to see all the files in any directory or filesystem.

Example: $ ls : This will list all the files under which this command is run.
$ ls -al : This will show all the files including hidden files in Linux system.

8. cd: This command stands for change directory and is used to go to a particular directory. It is similar to the windows command prompt command.

Example: $ cd / : Will change your directory to root (/).
$ cd /var : Will make /var your present working directory.

9. cp: This command is used to copy files from one directory to another or within a directory with different names. This Linux command is extensively used for taking backup of any file.

Example: $ cp /etc/test1 /etc/test2 : This will copy test1 file in /etc with new name test2 in same directory etc. If you are currently in /etc only, then you can directly use file name.

$ cp -p /etc/passwd /etc/passwd.backup : Suppose you want to take a backup of your /etc/passwd files, then you can use the above command to take a backup of passwd file with all permission as the original file.

10. mv: This is move command and is used to move the file from one location to another. Don’t confuse this with Copy command. This command can also be used to rename any file.

How to use the cd command on linux

Example: $ mv testfile.txt testfile2.txt : As shown above this command will rename file with name testfile.txt to testfile2.txt

$ mv testfile.txt /home/pawan : Now this command will move testfile.txt from its present location to /home/pawan. Here our present working location is /home/pawan/tech2blog

11. cat: This command is used to see the content of any file. This command can also be used to copy text files, combine text files & create new text files.

Example: $ cat /etc/group : This command will display all the content in group file in /etc.

These were some of the very basic Linux/Unix commands which are used in the everyday life of a system administrator. Let us know how you like our post on basic Linux commands which we use frequently while working on the Unix environment.

You can also download your complete basic Linux/Unix command guide. If you like the post, please consider it sharing your friends.

dir command in Linux is used to list the contents of a directory.

How is dir command different from ls?

dir command differs from ls command in the format of listing contents that is in default listing options.
By default, dir command lists the files and folders in columns, sorted vertically and special characters are represented by backslash escape sequences. But unlike ls, when the output is on terminal, it does not produce colored output as ls does.

SYNTAX:

Useful options for dir command

1. -a or –all option: It displays all the hidden files(starting with `.`) along with two files denoted by `.` and `..` which signals for current and previous directory respectively.
SYNTAX:

EXAMPLE:
How to use the cd command on linux

2. -A or –almost-all option: It is similar to -a option except that it does not display files that signals the current directory and previous directory.
SYNTAX:

EXAMPLE:
How to use the cd command on linux

3. -l –author option: Displays author of all the files. -l is required to display the contents in the form of a list.
SYNTAX:

EXAMPLE:
How to use the cd command on linux

4. -B or –ignore-backups option: Ignores listing of backed up files. These files end with a `

`.
SYNTAX:

5. –color option: (can be followed by =[TIME]).It is used to colorize the output. In the absence of time specification which can be auto, never or always, it colorizes the output always (default behavior).
SYNTAX:

EXAMPLE:
How to use the cd command on linux

6. -F, –classify option: Append indicator (one of */=>@|) to the file names which classifies them into their type. The meanings of symbols are as follows:

SYNTAX:

EXAMPLE:
How to use the cd command on linux

7. –file-type option: It is same as -F option, except that it does not append `*` to the executables.
SYNTAX:

EXAMPLE:
How to use the cd command on linux

8. –format=WORD option: It formats the listing of entries. The WORD can take the following values: across, commas, horizontal, long, single-column, verbose, vertical. The same can be achieved by passing -x, -m, -x, -l, -1, -l, -C options to dir command for each of the respective values.
SYNTAX:

EXAMPLE 1:
How to use the cd command on linux
EXAMPLE 2:
How to use the cd command on linux

9. –hide=PATTERN or –ignore=PATTERN option: It ignores files described by shell PATTERN while listing the contents of a directory.
SYNTAX:

EXAMPLE:
How to use the cd command on linux

10. -n, –numeric-uid-gid option: This option is similar to the long listing that is -l option except that it lists numeric user and group IDs.
SYNTAX:

11. -r, –reverse option: List files in reverse order while sorting.
SYNTAX:

EXAMPLE:
How to use the cd command on linux

12.-R, –recursive option: List subdirectories recursively.
SYNTAX:

EXAMPLE:
How to use the cd command on linux

13.–sort=PARAMETER: To list files in a sorted manner described by the PARAMETER. The PARAMETER can take the following values: none (-U), size (-S), time (-t), version (-v), extension (-X).Instead of passing –sort option, the flags indicated in the brackets can directly be passed as options to sort the listing.
SYNTAX:

EXAMPLE 1:
How to use the cd command on linux
EXAMPLE 2:
How to use the cd command on linux

14. –help option: Display the help options and exit.
SYNTAX:

EXAMPLE:
How to use the cd command on linux

15. –version option: Outputs version information and exit.
SYNTAX: