
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 located in the user's home directory. Moving around the file system requires the use of cd.
Per accedir al dorsièr raiç, picatz :
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.Per remontar d'un nivèl dins l'arborescéncia dels dorsièrs, picatz :
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.
Used with the -l option, ls outputs other information along with the filename, such as the permissions on the file, the file's owner, and more.
Used with the -al options, ls outputs the information associated with the -l option in addition to showing hidden files (a option).
The touch command is used either to change a file's access and modification timestamps or to create a new empty file. For example,
touch foo
will create a new empty file named foo
. If
foo
is already a file, then using touch
will update the timestamps on the file which will show
the last time a file was touched.
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!