$ cd foo

To change back to the directory you were in before the last cd command:

$ cd -

To change to your home directory:

$ cd  

To change to the book directory within your home directory, regardless of the current working directory:

$ cd ~/book

To change to jason 's home directory:

$ cd ~ jason/

4.3.1.7. Creating and removing directories from the command line

To create a directory from the command line, use the mkdir command:

$ mkdir newdirectory

This will create newdirectory in the current working directory. You could also specify the directory name using an absolute or relative-to-home pathname.

To create a chain of directories, or a directory when one or more of the parent directories might not exist, use the -p (path) option:

$ mkdir -p foo/bar/baz/qux

This has the side effect of turning off any warning messages if the directory already exists.

To delete a directory that is empty, use rmdir :

$ rmdir newdirectory

This will fail if the directory is not empty. To delete a directory as well as all of the directories and files within that directory, use the rm (remove) command with the -r (recursive) option:

$ rm -r newdirectory

rm -r can delete hundreds or thousands of files without further confirmation. Use it carefully!

4.3.1.8. Copying files

To copy a file, use the cp command with the source and destination filenames as positional arguments:

$ cp /etc/passwd /tmp/passwd- copy

This will make a copy of /etc/passwd named /tmp/passwd- copy . You can copy multiple files with a single cp command as long as the destination is a directory; for example, to copy /etc/passwd to /tmp/passwd and /etc/hosts to /tmp/hosts :

$ cp /etc/passwd /etc/hosts /tmp

4.3.1.9. Renaming and moving files

In Linux, renaming and moving files are considered the same operation and are performed with the mv command. In either cases, you're changing the pathname under which the file is stored without changing the contents of the file.

To change a file named yellow to be named purple in the current directory:

$ mv yellow purple

To move the file orange from jason 's home directory to your own:

$ mv ~jason/orange ~

4.3.1.10. Removing files

The rm command will remove (delete) a file:

$ rm badfile

You will not be prompted for confirmation as long as you are the owner of the file. To disable confirmation in all cases, use -f (force):

$ rm -f badfile

Or to enable confirmation in all cases, use -i (interactive):

$ rm -i badfile

rm: remove regular empty file Q

badfile

' ?

y

-f and -i can also be used with cp and mv .

The graphical desktop tools don't directly delete files; they relocate them to a hidden directory named

Вы читаете Fedora Linux
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату