
The pwd command displays the directory where the user is currently located. (pwd stands for “print working directory”). For example, typing
pwd
while in the Desktop
will show /home/[username]/Desktop
.
Note
Konsole also displays this information in both the tab and title bar of its window.
The cd command changes directories. (cd stands for “change directory”). When a terminal window is opened, it will be in the user's home directory. Moving around the file system requires the use of the cd.
To navigate into the root directory, type:
cd /
To navigate to the current user's home directory, type:
cd
or
cd ~
Note
The ~ character represents the current user's home directory. As shown above, cd ~ is equivalent to cd /home/username/. However, when running a command as root (using sudo, for example), ~ points to
/root
. When running a cd command with sudo, the full path to the home directory must be given.To navigate up one directory level, type:
cd ..
To navigate up two directory levels, type:
cd ../../
To navigate to the previous directory (go back), type:
cd -
To navigate through multiple levels of directories at once, specify the full directory path. For example, type:
cd /var/log
to go directly to the
/log
subdirectory of/var/
. For another example, typing:cd ~/Desktop
moves to the
Desktop
subdirectory inside the current user's home directory.
The ls command outputs a list of the files in the current directory. (ls is short for “list”). For example, typing
ls ~
will display the files that are in the current user's home directory.
如果使用时加上 -l 选项,ls 将输出文件名和其他信息,如文件权限、文件所有者等。
如果使用时加上 -al 选项,ls 除输出与 -l 选项有关的信息外,还显示的隐藏文件(a 选项)。
touch(触摸) 用来修改文件的访问和修改时间戳,或者创建一个新的空文件。例如,
touch foo
将会创建一个名为 foo
的文件。如果 foo
已经存在,则 touch 会修改该文件的时间戳,时间戳会显示文件被接触过了。
The mkdir command is used to create a new directory. (mkdir stands for “make directory”). To create a new directory named foobar
, type:
mkdir foobar
The cp command makes a copy of a file or directory. (cp is short for “copy”). To make an exact copy of foo
and name it bar
, type:
cp foo bar
To make an exact copy of the foo_dir
directory and name it bar_dir
, type:
cp -r foo_dir bar_dir
The mv command moves a file or directory to a different location or will rename a file or directory. (mv is short for “move”). To rename the file foo
to bar
, type:
mv foo bar
To move the file foo
into the current user's Desktop
directory, type:
mv foo ~/Desktop
This will not rename foo
to Desktop
because foo
is a file and Desktop
is a directory.
The rm command is used to delete files and directories. (rm is short for “remove”). To delete the file foo
for the current directory, type:
rm foo
By default, rm will not remove directories. To remove a directory, you must use the -r option (also can be entered as either -R or --recursive). For example,
rm -r foobar
or
rm -R foobar
or
rm --recursive foobar
will remove the directory foobar
, and all of its contents!