Linux File Commands


File Administration

ls [option(s)] [file(s)]

If you run ls without any additional parameters, the program will list the contents of the current directory in short form.

-l detailed list

-a displays hidden files

cp [option(s)] sourcefile targetfile

Copies sourcefile to targetfile.

-i Waits for confirmation, if necessary, before an existing targetfile is overwritten

-r Copies recursively (includes subdirectories)

mv [option(s)] sourcefile targetfile

Copies sourcefile to targetfile then deletes the original sourcefile.

-b Creates a backup copy of the sourcefile before moving

-i Waits for confirmation, if necessary, before an existing targetfile is overwritten

rm [option(s)] file(s)

Removes the specified files from the file system. Directories are not removed by rm unless the option -r is used.

-r  Deletes any existing subdirectories

-i Waits for confirmation before deleting each file.

ln [option(s)] sourcefile targetfile

Creates an from the sourcefile to the targetfile, under a different name. Normally, such a link points directly to the sourcefile on one and the same file system. However, if ln is executed with the -s option, it creates a symbolic link that only points to the directory where the sourcefile is located, thus enabling linking across file systems.

-s  Creates a symbolic link

cd [options(s)] [directory]

Changes the current directory. cd without any parameters changes to the user’s home directory.

mkdir [option(s)] directoryname

Creates a new directory.

rmdir [option(s)] directoryname

Deletes the specified directory, provided it is already empty.

chown [option(s)] file(s)

Transfers the ownership of a file to the user with the specified user name.

-R  Changes files and directories in all subdirectories.

chgrp [option(s)] groupname file(s)

Transfers the group ownership of a given file to the group with the specified group name. The file owner can only change group ownership if a member of both the existing and the new group.

chmod [options] mode file(s)

Changes the access permissions.

The mode parameter has three parts: group, access, and access type. group accepts the following characters:

u – user

g – group

o – others

For access, access is granted by the + symbol and denied by the – symbol.

The access type is controlled by the following options:

r – read

w – write

x – eXecute — executing files or changing to the directory.

s – Set uid bit — the application or program is started as if it were started by the owner of the file.

gzip [parameters] file(s)

This program compresses the contents of files, using complex mathematical algorithms. Files compressed in this way are given the extension .gz and need to be uncompressed before they can be used. To compress several files or even entire directories, use the tar command.

-d   Decompresses the packed gzip files so they return to their original size and can be processed normally (like the command gunzip).

tar options archive file(s)

The tar puts one file or (usually) several files into an archive. Compression is optional.

tar is a quite complex command with a number of options available. The most frequently used options are:

-f   Writes the output to a file and not to the screen as is usually the case

-c   Creates a new tar archive

-r   Adds files to an existing archive

-t   Outputs the contents of an archive

-u  Adds files, but only if they are newer than the files already contained in the archive

-x  Unpacks files from an archive (extraction)

-z  Packs the resulting archive with gzip

-j  Compresses the resulting archive with bzip2

-v  Lists files processed

The archive files created by tar end with .tar. If the tar archive was also compressed using gzip, the ending is .tgz or .tar.gz. If it was compressed using bzip2, .tar.bz2.

locate pattern(s)

The locate command can find in which directory a specified file is located. The program is very speedy, as it uses a database specifically created for the purpose (rather than searching through the entire file system). This very fact, however, also results in a major drawback: locate is unable to find any files created after the latest update of its database.

The database can be generated by root with updatedb.

updatedb [options(s)]

This command performs an update of the database used by locate. To include files in all existing directories, run the program as root. It also makes sense to place it in the background by appending an ampersand (&), so you can immediately continue working on the same command line (updatedb &).

find [option(s)]

The find command allows you to search for a file in a given directory. The first argument specifies the directory in which to start the search. The option -name must be followed by a search string.  Unlike locate, which uses a database, find scans the actual directory.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.