Navigating the Filesystem

By default, the prompt looks like the following:

[ankit@infinity ~]$

The first word before the @ symbol i.e "ankit" in this case is the username of the person currently logged in, and the word after the @ symbol is the hostname of the system. The part that follows the space after the hostname '~' is referred to as the current working directory. In this case, the ~ symbol means that the current working directory is the home directory of the user. When you start a terminal, the default directory is your home directory.

To change to a different directory, use the cd command. The can either be the full path to the directory or a directory relative to the current directory.

Notice that the shell prompt changes as you change directories. If you change to the documents/ directory, the prompt changes to the following:

[ankit@infinity documents]$

Notice that the prompt does not show where the current working directory is relative to the entire filesystem. It just shows the name of the current directory by itself.

To output the full path to the current working directory, execute the pwd command.

To create a directory, use the mkdir command. Again, the can be relative to the current directory or it can be the full path.


To remove a directory, invoke the rmdir command, where is a directory within the current directory or the full path to the directory. If any files are still in the directory , the error message Directory not empty will be displayed, and the directory will not be deleted. This prevents users from removing a directory that still contains files.To force the removal of a directory with all the files and subdirectories within that directory, use the rm -rf command. This command does not ask you to confirm the deletion, and there is no way to reverse the removal of the files and directories. Use extreme caution with this command. Double-check the directory specified before pressing Enter to execute the removal.

To remove a file, use the rm command. If only the filename is specified, it must be in the current working directory.

To view the contents of a current directory, execute the ls command, or use the ls command to view the contents of . As with the other commands discussed, can be relative to the current working directory or the full path to a directory. The ls command accepts the * wildcard character. For example, to list all the OpenOffice.org text documents, use the ls *.odt command, or the ls status* to find all files whose filename begins with status. Multiple wildcards can be used such as ls *status* to list all files that have status somewhere in their name.

To copy a file from one location to another, use the cp , where is the file to copy and is the directory or filename to copy it to.

When a file is moved, the file no longer exists in the original location. The mv command is similar to the cp command. The only difference is that the original file will no longer exist after the move operation. Multiple files can be specified as the for both the cp and mv commands, and both commands accept the * wildcard. For example, the mv *.txt textfiles/ command moves all files that end in .txt to the textfiles/ directory in the current working directory. Or, multiple files can be specified using their filenames. 






Related Posts:-



Comments

0 Responses to "Navigating the Filesystem"

Post a Comment

 

Managing Shell And its Secrets

Subscribe To Get Update On Mobile

Subscribe
Get updates of latest post on your mobile free