File status/control commands
ls [-options] [arguments] # list files command.
lists contents of current directory.
lists contents of named directory.
confirms existence of named file.
Options
-a # lists all files in current/named directory including hidden (dot) files.
-d directory # lists information about directory rather than its contents.
-l # long listing, shows :
- permissions
- link count, number of names associated with file.
- owner ID
- group ID
- size
- last modification date
ls -l # shows last time file data modified
ls -lc # shows last time file status (inode) modified
ls -lu # shows last time file was accessed
- filename
-n # long listing, but user and group names replaced by numeric values.
whereis cmd-name # lists available alternative versions of a
command. Also man pages and source files.
stat filename # shows status and permissions of named file. Filename
must exist.
stat file # verbose list about file.
stat -c "%a %n" file # lists just permissions as numeric and filename.
file filename # display basic file type of named file.
Some possible file types :
text
shell script
compiled
directory
symbolic-file
touch target-file # updates the time-stamp on the file
if target-file doesn't exist, create empty regular file.
Options
- touch -a file
- modify only access time
- touch -m file
- modify only modification time
- touch -c file
- don't create file
- Other options - man touch
cp source destination # copies contents of file and assigns
a name to new file.
cp source-file target-file
If target-file is existing regular file, data will be overwritten.
cp source-file1 source-file2 target-directory
File[s] will be copied into target-directory.
Cannot copy directory without use of -R option.
Options
-i file1 file2 # interactive, if file2 exists, check before overwriting.
-p file1 file2 # preserve, when copying file, duplicate ownership and
permissions.
-f file1 file2 # force, even if target file already exists and not writable.
Doesn't work if you don't own target.
-r, -R source-dir target-dir #recursive
- copies directory and contents to new directory
- required to copy directories.
- if target-dir exists as a directory, source-dir will be copied into it
with source-dir name.
- if target-dir does not exist, a copy of source-dir will be created with
the new name.
mv source destination # move or rename file.
mv old-file new-file
mv file-list target-directory
- if 'new-file' will be in same directory, becomes a rename.
- if source and destination on same drive partition, filename entry in
directories modified but file contents not touched.
- if moving file-list, target must be existing directory with write, execute
permissions for the user.
- can be used move directories. If target doesn't exist, becomes a rename
If target exists and a directory, moved inside target.
Options :
-i file1 file2 # interactive, if file2 exists, check before overwriting.
-p file1 file2 # preserve, when copying file, duplicate ownership and
permissions.
-f file1 file2 # force if target file already exists and not writable.
Doesn't work if you don't own the file.
mkdir dirname # create a directory file
-m # mode, set permission access while creating.
-p # parent, create parents of target if not already in existence.
rmdir dirname # remove a directory file
directory to be removed must be empty of any files.
-p # parent, remove parents of target. Parents have to be empty of any
other files.
ln target new-name # links a new filename to a target
filename. Type of alias.
ln target new-name
- hard link, no option
- target (filename being linked to) must be a regular, named pipe, or
symbolic file.
- new-name must be created on the same file-system as the existing-file.
- user must have execute permissions to all directories in path.
- new-name takes entry in directory list but no other resources.
- if target owned by someone else, you must have write permissions on target.
Note : this is generally a bad idea anyways.
- file exists as long as at least one name linked to it.
ln -s target new-name # symbolic or soft link.
- creates a file called new-name containing the target argument.
- new-name file tagged as a symbolic link file.
- can link to non-regular files, such as a directory.
- can link to a file on another partition, drive, or even system.
- can even link to a file that does not exist (yet).
i.e set up software where a specific device driver not yet determined.
- target can be truly deleted.
- can link to another symbolic link.
- system limits traversal of chain links to prevent endless looping.
Other options :
- -i # ask before overwriting
- -f # force, do not ask, even if write permissions say no.
- -L # logical, if target symbolic, dereference, find its target before
linking, will follow chained links.