Kommandon för filer och kataloger

pwd - visar aktuell katalog

Kommandot pwd visar katalogen som användaren för närvarande befinner sig i (pwd betyder “print working directory”). Till exempel, skriv

pwd

när du är i katalogen Skrivbord kommer visa /home/[username]/Skrivbord.

Note

Konsole visar även denna information i både fliken och titelraden för fönstret.

cd - ändra katalog

Kommandot cd skiftar katalog (cd står för “change directory”). När ett terminalfönster är öppet, kommer den att peka mot användarens hemkatalog. För att förflytta sig runt i filsystemet krävs det att man använder cd.

  • Skriv

    cd /

    för att navigera till rotkatalogen

  • För att navigera till den nuvarande användarens hemkatalog, skriv:

    cd

    eller

    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.

  • Skriv

    cd ..

    för att navigera en katalognivå uppåt

  • 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.

ls - lista filer

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).

touch - skapa tom fil

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.

mkdir - skapa katalog

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

cp - kopiera filer eller kataloger

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

mv - flytta filer eller kataloger

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.

rm - byt namn på filer eller kataloger

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!