Top-Rated Free Essay
Preview

Linux Commands

Good Essays
5778 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Linux Commands
Linux Commands pwd Print Working Directory (shell builtin)
Syntax
pwd [-LP]
Options
-P : The pathname printed will not contain symbolic links.
-L : The pathname printed may contain symbolic links
The default action is to show the current folder as an absolute path.
All components of the path will be actual folder names - none will be symbolic links. ls List information about files.
Syntax
ls [Options]... [File]...
Key
Sort entries alphabetically if none of -cftuSUX nor --sort.
-a, --all Do not hide entries starting with .
-A, --almost-all Do not list implied . and ..
-c Sort by change time; with -l: show ctime
-d, --directory List directory entries instead of contents
-f Do not sort, enable -aU, disable -lst
-i, --inode Print index number of each file
-k, --kilobytes Like --block-size=1024
-l Use a long listing format
-L, --dereference List entries pointed to by symbolic links characters specially)
-r, --reverse Reverse order while sorting
-R, --recursive List subdirectories recursively
-s, --size Print size of each file, in blocks
-t sort by modification time
-u sort by last access time; with -l: show atime
-U do not sort; list entries in directory order
-v sort by version
-1 list one file per line
--help display help and exit
--version output version information and exit
The most common options are -a (all files) and -l (long or details)
Examples
# List the contents of your home directory
$ ls ~
# list everything in a vertical list:
$ ls -al total 109 drwxr-xr-x 18 root root 4096 Jun 9 21:12 ./ drwxr-xr-x 18 root root 4096 Jun 9 21:12 ../ drwxr-xr-x 2 root root 4096 Jun 9 21:14 bin/ drwxr-xr-x 3 root root 1024 Jun 9 20:32 boot/ drwxr-xr-x 6 root root 36864 Jul 12 10:26 dev/ drwxr-xr-x 34 root root 4096 Jul 12 10:25 etc/
^
the first column is the file type d = directory f = file
# List the directories in the current directory:
$ ls -d */
# list ALL subdirectories
$ ls *
The default behaviour of ls is to only pass color control codes to tty output --color=auto.
To pipe the output to a second command complete with color codes then set --color=always cd Change Directory - change the current working directory to a specific Folder.
Syntax
cd [Options] [Directory]
Key
-P Do not follow symbolic links
-L Follow symbolic links (default)
If directory is not given, the value of the HOME shell variable is used.
If the shell variable CDPATH exists, it is used as a search path.
If directory begins with a slash, CDPATH is not used.
If directory is `-', this will change to the previous directory location (equivalent to $OLDPWD ).
The return status is zero if the directory is successfully changed, non-zero otherwise.
Examples
Move to the sybase folder
$ cd /usr/local/sybase
$ pwd
/usr/local/sybase
Change to another folder
$ cd /var/log
$ pwd
/var/log
Quickly get back
$ cd -
$ pwd
/usr/local/sybase
move up one folder
$ cd ..
$ pwd
/usr/local/
$ cd (Back to your home folder) who Print who is currently logged in
Syntax
who [options] [file] [am i]
Options
-m
Print the current user id, name and domain
(Same as `who am i')
-q
--count
Print only the login names and the number of users logged on.
Overrides all other options.
-i
The who command differs from whoami in that it provides a list of all users currently logged into the system as well as additional information about each of those users (including login times and terminal numbers). It also differs in that, in the event of a change in ownership of a login session through the use of the su command, it reports the original owner of the session, whereas whoami provides the user name of the effective (i.e., current) owner of the session. If given no non-option arguments, `who' prints the following information for each user currently logged on: login name, terminal line, login time, remote hostname or X display.
If given one non-option argument, `who' uses that instead of `/var/run/utmp' as the name of the file containing the record of users logged on. `/var/run/wtmp' is commonly given as an argument to `who' to look at who has previously logged on.
If given two non-option arguments, `who' prints only the entry for the user running it
(determined from its standard input), preceded by the hostname. Traditionally, the two arguments given are `am i', as in `who am i'. whoami Print the current user id and name.
Syntax
whoami [options]
Options
--help Display Help
--version Display program version info whoami produces the same result as the id -un command (the id command by default provides more detailed informatio which Locate a program file in the user's path.
For each of its arguments which prints to stdout the full path of the executable(s). It does this by searching the directories listed in the environment variable PATH.
Syntax
which [options] [--] program_name [...]
Options
--all, -a
Print all matching executables in PATH, not just the first. --read-alias, -i
Read aliases from stdin, reporting matching ones on stdout. This is useful in combination with using an alias for which itself. For example alias which='alias | which -i'. cp Copy one or more files to another location
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Syntax
cp [options]... Source Dest cp [options]... Source... Directory
Key
-a, --archive same as -dpR
-b, --backup make backup before removal
-d, --no-dereference preserve links
-f, --force remove existing destinations, never prompt
-i, --interactive prompt before overwrite
-l, --link link files instead of copying
-p, --preserve preserve file attributes if possible
-P, --parents append source path to DIRECTORY
-r copy recursively, non-directories as files
--sparse=WHEN control creation of sparse files
-R, --recursive copy directories recursively
-s, --symbolic-link make symbolic links instead of copying
Examples
Copy demofile to demofile.bak :
$ cp demofile demofile.bak or $ cp demofile{,.bak}
Copy demofile.txt to demofile.bak :
$ file="demofile.txt"
$ cp $file ${file%.*}.bak
Copy floppy to home directory:
$ cp -f /mnt/floppy/* ~ mv Move or rename files or directories.
SYNTAX
mv [options]... Source Dest mv [options]... Source... Directory
If the last argument names an existing directory, `mv' moves each other given file into a file with the same name in that directory. Otherwise, if only two files are given, it renames the first as the second. It is an error if the last argument is not a directory and more than two files are given.
OPTIONS
-b
--backup
Make a backup of each file that would otherwise be overwritten or removed. -f
--force
Remove existing destination files and never prompt the user.
-i
--interactive
Prompt whether to overwrite each existing destination file, regardless of its permissions. If the response does not begin with `y' or `Y', the file is skipped.
--help display help and exit
--version output version information and exit
Examples
Rename the file apple as orange.doc: mv apple orange.doc
Move orange.doc to the Documents folder: mv orange.doc ~/Documents/orange.doc
Rename a bunch of file extensions
e.g. change *.txt into *.htm for f in *.txt; do mv ./"$f" "${f%txt}htm"; done
`mv' can move only regular files across filesystems.
If a destination file exists but is normally unwritable, standard input is a terminal, and the `-f' or
`--force' option is not given, `mv' prompts the user for whether to replace the file. (You might own the file, or have write permission on its directory.) If the response does not begin with `y' or
`Y', the file is skipped. rm Remove files (delete/unlink)
Syntax
rm [options]... file...
Options
-d, --directory unlink directory, even if non-empty (super-user only)
-f, --force ignore nonexistent files, never prompt
-i, --interactive prompt before any removal
-r, -R, --recursive remove the contents of directories recursively
-v, --verbose explain what is being done
--help display this help and exit
--version output version information and exit
To remove a file you must have write permission on the file and the folder where it is stored. rm -rf will recursively remove folders and their contents
The OWNER of a file does not need rw permissions in order to rm it.
Undeletable files
The rm command accepts the `--' option which will cause it to stop processing flag options from that point forward. This allows the removal of file names that begin with a dash (`-'). rm -- -filename
Alternatively use an absolute or relative path reference. rm /home/user/-filename rm ./-filename
To delete a file with non-printable characters in the name: `bad file name' Use the shell wildcard
"?" for each character rm bad?file?name
Older file systems such as ext2fs, perform badly for massive bulk deletes. The newer ext3fs doesn't have this performance problem.
To remove a very large number of files from a directory it can be quicker to rm them one at a time in a loop: find my_dir -type f | while read -r; do rm -v "$REPLY"; sleep 0.2; done mkdir Create new folder(s), if they do not already exist.
SYNTAX
mkdir [Options] folder... mkdir "Name with spaces"
OPTIONS
-m, --mode=MODE set permission mode (as in chmod), not rwxrwxrwx - umask
-p, --parents no error if existing, make parent directories as needed
--verbose print a message for each created directory mkdir creates the standard entries . (dot) for the current folder and .. (dot dot) for its parent touch Change file timestamps, change the access and/or modification times of the specified files.
Syntax
touch [options]... File...
Options
-a
--time=atime
--time=access
--time=use
Change the access time only.
-c
--no-create
Do not create files that do not exist.
-d
--date=time
Use time instead of the current time. It can contain month names, timezones, `am' and `pm', etc.
-m
--time=mtime
--time=modify
Change the modification time only.
-r FILE
--reference=FILE
Use the times of the reference FILE instead of the current time.
-t [[CC]YY]MMDDhhmm[.ss]
Set to a specific time.
The -t argument will accept four-digit or two-digit years, specifying the seconds is optional. If no digits of the year are specified, the argument is interpreted as a date in the current year.
If two-digit year is specified, then CC is 20 for years in the range 0 ... 68, and 19 for year in 69 ...
99.
If the first FILE would be a valid argument to the `-t' option and no timestamp is given with any of the `-d', `-r', or `-t' options and the `--' argument is not given, that argument is interpreted as the time for the other files instead of as a file name.
Any FILE that does not exist is created empty.
If changing both the access and modification times to the current time, `touch' can change the timestamps for files that the user running it does not own but has write permission for.
Otherwise, the user must own the files.
Examples
Create/datestamp one file called sample.txt: touch sample.txt
Create/datestamp 10 files called file1, file2 etc: touch file{1,2,3,4,5,6,7,8,9,10}
Create/datestamp 100 files called file1, file2 etc: for i in $(seq 1 100); do echo -n "file${i} "; touch file${i} 2>&1; done hostname Print or set system name
SYNTAX
hostname [name]
With no arguments, `hostname' prints the name of the current host system. With one argument, it sets the current host name to the specified string. You must have appropriate privileges to set the host name cal Display a calendar
Syntax
cal [-mjy] [[month] year]
Options:
-m Display monday as the first day of the week.
-j Display julian dates (days one-based, numbered from January 1).
-y Display a calendar for the current year.
A single parameter specifies the 4 digit year (1 - 9999) to be displayed.
Two parameters denote the Month (1 - 12) and Year (1 - 9999).
If arguments are not specified, the current month is displayed.
A year starts on 01 Jan. cat Concatenate and print (display) the content of files.
Syntax
cat [Options] [File]...
Concatenate FILE(s), or standard input, to standard output.
-A, --show-all equivalent to -vET
-n, --number number all output lines
--help display this help and exit
--version output version information and exit
With no FILE, or when FILE is -, read standard input.
Examples:
Display a file (this actually works by concatenating the file with STDOUT)
$ cat myfile.txt
Concatenate two files:
$ cat File1.txt File2.txt > union.txt
If you need to combine two files but also eliminate duplicates, this can be done with sort unique:
$ sort -u File1.txt File2.txt > unique_union.txt
Put the contents of a file into a variable
$ my_variable=`cat File3.txt` mount mount a file system
All files accessible in a Unix system are arranged in one big tree, the file hierarchy, rooted at /.
These files can be spread out over several devices. The mount command serves to attach the file system found on some device to the big file tree.
SYNTAX
mount [-fnrsvw] [-o options [,...]] device | dir
OPTIONS
-a Mount all filesystems (of the given types) mentioned in fstab.
-h Print a help message.
-V Output version.
-v Verbose mode.
Three forms of invocation do not actually mount anything: print a help message: mount -h print a version string: mount -V list all mounted file systems of type 'type' mount [-t type]
Most devices are indicated by a file name (of a block special device), like /dev/sda1, but there are other possibilities. For example, in the case of an NFS mount, device may look like knuth.cwi.nl:/dir. It is possible to indicate a block special device using its volume label or UUID
(see the -L and -U options below).
The file /etc/fstab (see fstab), may contain lines describing what devices are usually mounted where, using which options. logout Exit a login shell.
SYNTAX
logout [n]
Returns a status of n to the shell's parent.
A login shell, is your topmost shell, and is started when you log in.
When you terminate a login shell (via the commands `exit', `logout,' or the end of file [^D]), you are logged out completely.
Sub-Shells
A `sub-shell' is a shell created after login, either by loading a new shell or opening a window with a graphics interface. A sub-shell usually will not accept the command `logout' to terminate, you must use `exit' or ^D.
When you terminate a sub-shell, you are returned to the process or shell that created it.
Example (starting from a bash shell)
$ tcsh
% # now in the tcsh shell
% exit
$ # now back in the bash shell
$ logout echo Display message on screen, writes each given STRING to standard output, with a space between each and a newline after the last one.
Syntax
echo [options]... [string]...
Options
-n
Do not output the trailing newline.
-E
Disable the interpretation of the following backslash-escaped characters
-e
Enable interpretation of the following backslash-escaped characters in each STRING:
\a alert (bell)
\b backspace
\c suppress trailing newline
\e escape
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\NNN
the character whose ASCII code is NNN (octal); if NNN is not a valid octal number, it is printed literally.
\xnnn
the character whose ASCII code is the hexadecimal value nnn (one to three digits) echo is a BASH built-in command wget wc
Print byte, word, and line counts, count the number of bytes, whitespace-separated words, and newlines in each given FILE, or standard input if none are given or for a FILE of `-'.
Syntax
wc [options]... [file]...
Options
-c
--bytes
--chars
Print only the byte counts.
-w
--words
Print only the word counts.
-l
--lines
Print only the newline counts.
-L
--max-line-length
Print only the length of the longest line per file, and if there is more than one file it prints the maximum (not the sum) of those lengths.
`wc' prints one line of counts for each file, and if the file was given as an argument, it prints the file name following the counts.
If more than one FILE is given, `wc' prints a final line containing the cumulative counts, with the file name `total'. The counts are printed in this order: newlines, words, bytes.
Examples
Count the number of lines in file1.txt
$ wc -l < file1.txt
Count the number of words in file2.txt
$ wc -w file2.txt
Count the number of words by pasting from the clipboard:
$ wc -l
(paste the list into the window and then type CTRL-D) dd Convert and copy a file, write disk headers, boot records, create a boot floppy. dd can make an exact clone of an (unmounted) disk, this will include all blank space so the output destination must be at least as large as the input.
Syntax
dd [Options]
Key
if=FILE
Input file : Read from FILE instead of standard input. of=FILE Output file : Write to FILE instead of standard output. Unless
`conv=notrunc'
is given, `dd' truncates FILE to zero bytes (or the size specified with `seek='). ibs=BYTES Read BYTES bytes at a time. obs=BYTES Write BYTES bytes at a time. bs=BYTES Block size, both read and write BYTES bytes at a time. This overrides
`ibs'
and `obs'. cbs=BYTES Convert BYTES bytes at a time. skip=BLOCKS Skip BLOCKS `ibs'-byte blocks in the input file before copying. seek=BLOCKS Skip BLOCKS `obs'-byte blocks in the output file before copying. count=BLOCKS Copy BLOCKS `ibs'-byte blocks from the input file, instead of everything until the end of the file. conv=CONVERSION[,CONVERSION]... Convert the file as specified by the CONVERSION argument(s).
(No spaces around any comma)
Conversions:
`ascii' Convert EBCDIC to ASCII.
`ebcdic' Convert ASCII to EBCDIC.
`ibm' Convert ASCII to alternate EBCDIC.
`block' For each line in the input, output `cbs' bytes, replacing the input newline with a space and padding with spaces as necessary. `unblock' Replace trailing spaces in each `cbs'-sized input block with a newline. `lcase' Change uppercase letters to lowercase.
`ucase' Change lowercase letters to uppercase.
`swab' Swap every pair of input bytes. GNU `dd', unlike others, works when an odd number of bytes are read--the last byte is simply copied (since there is nothing to swap it with).
`noerror' Continue after read errors.
`notrunc' Do not truncate the output file.
`sync' Pad every input block to size of `ibs' with trailing zero bytes. The numeric-valued options (BYTES and BLOCKS) can be followed by a multiplier: `b'=512,
`c'=1, `w'=2, `xM'=M, or any of the standard block size suffixes like `k'=1024.
Examples:
Clone one hard drive onto another
$ dd if=/dev/sda of=/dev/sdb
Clone a hard drive to an image file
$ dd if=/dev/hda of=/image.img
Clone a hard drive to a zipped image file in 100Mb blocks
$ dd if=/dev/hda bs=100M | gzip -c > /image.img
Create a boot floppy:
$ dd if=boot.img of=/dev/fd0 bs=1440 test Evaluate a conditional expression expr.
Syntax
test expr
[ expr
Options
Each operator and operand must be a separate argument. When the [ form is used, the last argument to the command must be a ]. Expressions may be combined using the following operators, listed in decreasing order of precedence.
! expr
True if expr is false.
( expr )
Returns the value of expr. This may be used to override the normal precedence of operators. expr1 -a expr2
True if both expr1 and expr2 are true. expr1 -o expr2
True if either expr1 or expr2 is true.
The test and [ builtins evaluate conditional expressions using a set of rules based on the number of arguments.
0 arguments
The expression is false.
1 argument
The expression is true if and only if the argument is not null.
2 arguments
If the first argument is `!', the expression is true if and only if the second argument is null. If the first argument is one of the unary conditional operators, the expression is true if the unary test is true. If the first argument is not a valid unary operator, the expression is false.
3 arguments
If the second argument is one of the binary conditional operators, the result of the expression is the result of the binary test using the first and third arguments as operands.
If the first argument is `!', the value is the negation of the two-argument test using the second and third arguments. If the first argument is exactly `(' and the third argument is exactly `)', the result is the one-argument test of the second argument. Otherwise, the expression is false. The `-a' and `-o' operators are considered binary operators in this case. 4 arguments
If the first argument is `!', the result is the negation of the three-argument expression composed of the remaining arguments. Otherwise, the expression is parsed and evaluated according to precedence using the rules listed above.
5 or more arguments
The expression is parsed and evaluated according to precedence using the rules listed above. The above applies to the BOURNE shell built-in, the BASH `test' command has the following additional options:
File type tests
These options test for particular types of files. All cases will only return True (0) if the file exists.
`-b file'
True if file is a Block special device.
`-c file'
True if file is a Character special device.
`-d file'
True if file is a Directory.
`-e file'
True if file Exists.
`-f file'
True if file is a regular File.
`-g file'
True if file has its set-group-id bit set.
`-G file'
True if file is owned by the current effective group id.
`-k file'
True if file has its "sticky" bit set.
`-h file'
`-L file'
True if file is a symbolic Link.
`-O file'
True if file is owned by the current effective user id.
`-p file'
True if file is a named Pipe.
`-r file'
True if file is readable.
`-S file'
True if file is a Socket.
`-s file'
True if file has a Size greater than zero.
`-t [FD]'
True if FD is opened on a terminal. If FD is omitted, it defaults to 1 (standard output).
`-u file'
True if file has its set-user-id bit set.
`-w file'
True if file is writable.
`-x file'
True if file is executable.
`file1 -ef file2'
True if file1 and file2 have the same device and inode numbers,
i.e., if they are hard links to each other.
File Age
These options test the file modification date.
`file1 -nt file2'
True if file1 is newer than file2.
`file1 -ot file2'
True if file1 is older than file2.
String tests
These options test string characteristics. Strings are not quoted for `test', though you may need to quote them to protect characters with special meaning to the shell, e.g., spaces.
`-z String'
True if the length of String is zero.
`-n String'
`String'
True if the length of String is nonzero.
`String1 = String2'
True if the strings are equal.
`String1 != String2'
True if the strings are not equal.
Numeric tests
Numeric relationals. The arguments must be entirely numeric (possibly negative), or the special expression `-l STRING', which evaluates to the length of STRING.
`ARG1 -eq ARG2'
`ARG1 -ne ARG2'
`ARG1 -lt ARG2'
`ARG1 -le ARG2'
`ARG1 -gt ARG2'
`ARG1 -ge ARG2'
These arithmetic binary operators return true if ARG1 is equal, not-equal, less-than, less-than-or-equal, greater-than, or greater-than-or-equal than ARG2, respectively.
For example: test -1 -gt -2 && echo yes
=> yes test -l abc -gt 1 && echo yes
=> yes test 0x100 -eq 1 error--> test: integer expression expected before -eq
Examples
$ ls -al total 67 drwxr-xr-x 18 root root 4096 Jun 9 21:12 ./ drwxr-xr-x 18 root root 4096 Jun 9 21:12 ../
-rw-rw-rw- 1 simon users 4096 Jun 9 07:30 london
-rwsrwsrwx 1 simon users 4096 Jun 9 07:32 aberdeen
-rw------- 1 simon users 4096 Jun 9 07:29 bristol
-rw-r--r-- 1 simon users 4096 Jun 9 07:29 bath
$
$ test -r paris
$ echo $?
1
$
Because the file `paris' is not Readable, the value returned is false (non zero) if [ "$LOGNAME" = "scott" ] then echo "Logged in as Scott" else echo "incorrect user" fi If the logname variable = scott then the test returns TRUE (0) chmod Change access permissions, change mode.
Syntax
chmod [Options]... Mode [,Mode]... file... chmod [Options]... Numeric_Mode file... chmod [Options]... --reference=RFile file...
Options
-f, --silent, --quiet suppress most error messages
-v, --verbose output a diagnostic for every file processed
-c, --changes like verbose but report only when a change is made
--reference=RFile use RFile's mode instead of MODE values
-R, --recursive change files and directories recursively
--help display help and exit
--version output version information and exit chmod changes the permissions of each given file according to mode, where mode describes the permissions to modify. Mode can be specified with octal numbers or with letters. Using letters is easier to understand for most people.
Permissions: 751 owner group other read write execute Numeric mode:
From one to four octal digits
Any omitted digits are assumed to be leading zeros.
The first digit = selects attributes for the set user ID (4) and set group ID (2) and save text image
(1)S
The second digit = permissions for the user who owns the file: read (4), write (2), and execute (1)
The third digit = permissions for other users in the file's group: read (4), write (2), and execute
(1)
The fourth digit = permissions for other users NOT in the file's group: read (4), write (2), and execute (1)
The octal (0-7) value is calculated by adding up the values for each digit
User (rwx) = 4+2+1 = 7
Group(rx) = 4+1 = 5
World (rx) = 4+1 = 5 chmode mode = 0755
Examples
chmod 400 file - Read by owner chmod 040 file - Read by group chmod 004 file - Read by world chmod 200 file - Write by owner chmod 020 file - Write by group chmod 002 file - Write by world chmod 100 file - execute by owner chmod 010 file - execute by group chmod 001 file - execute by world
To combine these, just add the numbers together: chmod 444 file - Allow read permission to owner and group and world chmod 777 file - Allow everyone to read, write, and execute file
Symbolic Mode
The format of a symbolic mode is a combination of the letters +-= rwxXstugoa
Multiple symbolic operations can be given, separated by commas.
The full syntax is [ugoa...][[+-=][rwxXstugo...]...][,...] but this is explained below.
A combination of the letters ugoa controls which users' access to the file will be changed:
User letter
The user who owns it u
Other users in the file's Group g
Other users not in the file's group o
All users a
If none of these are given, the effect is as if a were given, but bits that are set in the umask are not affected.
All users a is effectively user + group + others
The operator '+' causes the permissions selected to be added to the existing permissions of each file; '-' causes them to be removed; and '=' causes them to be the only permissions that the file has. The letters 'rwxXstugo' select the new permissions for the affected users:
Permission letter
Read r
Write w
Execute (or access for directories) x
Execute only if the file is a directory
(or already has execute permission for some user)
X
Set user or group ID on execution s
Save program text on swap device t
The permissions that the User who owns the file currently has for it u The permissions that other users in the file's Group have for it g
Permissions that Other users not in the file's group have for it o
Examples
Deny execute permission to everyone: chmod a-x file
Allow read permission to everyone: chmod a+r file
Make a file readable and writable by the group and others: chmod go+rw file
Make a shell script executable by the user/owner
$ chmod u+x myscript.sh
Allow everyone to read, write, and execute the file and turn on the set group-ID: chmod =rwx,g+s file
Notes:
When chmod is applied to a directory: read = list files in the directory write = add new files to the directory execute = access files in the directory chmod never changes the permissions of symbolic links. This is not a problem since the permissions of symbolic links are never used. However, for each symbolic link listed on the command line, chmod changes the permissions of the pointed-to file. In contrast, chmod ignores symbolic links encountered during recursive directory traversals.
This page documents the GNU version of chmod. date Display or change the date.
Syntax
date [option]... [+Format] date [option] [MMDDhhmm[[CC]YY][.ss]]
Format controls the output as follows. The only valid option for the second form
(MMDDhhmm[[CC]YY][.ss])will specify Coordinated Universal Time.
Interpreted sequences are:
Date:
D Date in mm/dd/yy format (06/14/06) x Date in standard format for locale (09/12/07 for English-US)
Year:
C Century (20 for 2006)
Y Year in 4-digit format (2006) y Year in 2-digit format (06)
G Same as 'Y' g Same as 'y'
Month:
b Month name - abbreviated (Jan)
B Month name - full (January) h Same as 'b' m Month number (06)
Week:
W Week of the year (00-52)
V Week of the year (01-53)
U Same as 'W'
Day:
a Day of the week - abbreviated name (Mon)
A Day of the week - full name (Monday) u Day of the week - number (Monday = 1) d Day of the month - 2 digits (05) e Day of the month - digit preceded by a space ( 5) j Day of the year - (1-366) w Same as 'u'
Time:
p AM or PM r Time in 12-hour format (09:15:36 AM)
R Time in 24-hour format - no seconds (17:45)
T Time in 24 hour format (17:45:52)
X Same as 'T'
Z Time zone offset from UTC (-07)
Hour:
H Hour in 24-hour format (17)
I Hour in 12 hour format (05) k Same as 'H' l Same as 'I' (Upper-case I = Lower-case L)
Minutes & Seconds:
M Minutes (35)
S Seconds (05) s Seconds elapsed since January 1, 1970 00:00:00 (1150451174.95705)
Here are the same format codes in alphabetical order:
%% a literal %
%a locale's abbreviated weekday name (Sun..Sat)
%A locale's full weekday name, variable length (Sunday..Saturday)
%b locale's abbreviated month name (Jan..Dec)
%B locale's full month name, variable length (January..December)
%c locale's date and time (Sat Nov 04 12:02:33 EST 1989)
%d day of month (01..31)
%D date (mm/dd/yy)
%e day of month, blank padded ( 1..31)
%h same as %b, locale's abbreviated month name (Jan..Dec)
%H hour :24 hour(00..23)
%I hour :12 hour(01..12)
%j day of year (001..366)
%k hour :24 hour(00..23)
%l hour :12 hour(01..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%p locale's AM or PM
%r time, 12-hour (hh:mm:ss [AP]M)
%s seconds since 00:00:00, Jan 1, 1970 (a GNU extension)
Note that this value is defined by the localtime system call. It isn't changed by the `--date' option.
%S second (00..60)
%t a horizontal tab
%T time, 24-hour (hh:mm:ss)
%U week number of year with Sunday as first day of week (00..53)
%V week number of year with Monday as first day of week (01..53)
If the week containing January 1 has four or more days in the new year, then it is considered week 1; otherwise, it is week 53 of the previous year, and the next week is week 1. (See the ISO 8601: 1988 standard.)
%w day of week (0..6); 0 represents Sunday
%W week number of year with Monday as first day of week (00..53)
%x locale's date representation (mm/dd/yy)
%X locale's time representation (%H:%M:%S)
%y last two digits of year (00..99)
%Y year (1970...)
%z RFC-822 style numeric timezone (-0500) (a nonstandard extension)
This value reflects the _current_ time zone.
It isn't changed by the `--date' option.
%Z time zone (e.g., EDT), or nothing if no time zone is determinable
This value reflects the _current_ time zone.
It isn't changed by the `--date' option.
By default, date pads numeric fields with zeroes. GNU date recognizes the following modifiers between % and a numeric directive.
- (hyphen) do not pad the field; useful if the output is intended for human consumption.
_ (underscore) pad the field with spaces; useful if you need a fixed number of characters in the output, but zeroes are too distracting.
The - and _ are GNU extensions. Here is an example illustrating the differences: date +%d/%m -d "Feb 1"
=> 01/02 date +%-d/%-m -d "Feb 1"
=> 1/2 date +%_d/%_m -d "Feb 1"
=> 1/ 2
Setting the time
If given an argument that does not start with +, date sets the system clock to the time and date specified by that argument (as described below). You must have appropriate privileges to set the system clock. The --date and --set options may not be used with such an argument. The -- universal option may be used with such an argument to indicate that the specified time and date are relative to Coordinated Universal Time rather than to the local time zone.
The argument must consist entirely of digits, which have the following meaning:
MM month
DD day within month
HH hour
MM minute
CC first two digits of year (optional)
YY last two digits of year (optional)
SS second (optional)
The `--set' option also sets the system clock; see the examples below.
Examples
$ date -d '1970-01-01 946684800 sec' +"%Y-%m-%d %T %z"
2000-01-01 00:00:00 +0000 du Disk Usage - report the amount of disk space used by the specified files and for each subdirectory. Syntax du [options]... [file]...
With no arguments, `du' reports the disk space for the current directory. Normally the disk space is printed in units of 1024 bytes, but this can be overridden
OPTIONS
`-a'
`--all'
Show counts for all files, not just directories.
`-b'
`--bytes'
Print sizes in bytes, overriding the default block size (*note
Block size::).
`-c'
`--total'
Print a grand total of all arguments after all arguments have been processed. This can be used to find out the total disk usage of a given set of files or directories.
`-h'
`--human-readable'
Append a size letter such as `M' for megabytes to each size.
Powers of 1024 are used, not 1000; `M' stands for 1,048,576 bytes.
Use the `-H' or `--si' option if you prefer powers of 1000.
`-k'
`--kilobytes'
Print sizes in 1024-byte blocks, overriding the default block size
(*note Block size::).
`-l'
`--count-links'
Count the size of all files, even if they have appeared already
(as a hard link). head Output the first part of files, prints the first part (10 lines by default) of each file.
SYNTAX
head [options]... [file]...
Options:
-NUMBER
Return the first NUMBER of lines from the file. (must be the first option specified)
-CountOptions
This option is only recognized if it is specified first. Count is a decimal number optionally followed by a size letter ('b', 'k',
'm' for bytes, Kilobytes or Megabytes) , or 'l' to mean count by lines, or other option letters
('cqv').
-c BYTES
--bytes=BYTES
Print the first BYTES bytes, instead of initial lines. Appending
'b' multiplies BYTES by 512, 'k' by 1024, and 'm' by 1048576.
-n N
--lines=N
Output the first N lines.
-q
--quiet
--silent
Never print file name headers.
-v
--verbose
Always print file name headers.
If no files are given (or if given a FILE of '-') head will read from standard input.
If more than one FILE is specified, 'head' will print a one-line header consisting of ==> FILE
NAME

You May Also Find These Documents Helpful

  • Powerful Essays

    Virtual Directories : Virtual Directories enable you to use a Web site to publish files located anywhere on the network.…

    • 1432 Words
    • 7 Pages
    Powerful Essays
  • Powerful Essays

    It is the directive that is used to change the location of the document root.…

    • 2385 Words
    • 10 Pages
    Powerful Essays
  • Satisfactory Essays

    What is the result of giving the ‘which’ utility the name of a command that resides in a directory that is not in your search path?…

    • 344 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Nt1330 Unit 3 Lab Report

    • 1967 Words
    • 8 Pages

    symbolic links are enabled by default. If you don't need them, you can disable them with the skip-symbolic-links option.…

    • 1967 Words
    • 8 Pages
    Powerful Essays
  • Powerful Essays

    Comp230-Intro to Scripting

    • 12553 Words
    • 51 Pages

    The Windows CLI command that is used to display the search path for the executable files is _________.…

    • 12553 Words
    • 51 Pages
    Powerful Essays
  • Good Essays

    Nt1430 Unit 2

    • 393 Words
    • 2 Pages

    IF it starts with / it is absolute value. If it does not contain a / or . it is a simple file.…

    • 393 Words
    • 2 Pages
    Good Essays
  • Good Essays

    It250

    • 272 Words
    • 2 Pages

    It is the directive that is used to change the location of the document root.…

    • 272 Words
    • 2 Pages
    Good Essays
  • Good Essays

    File Management in Unix

    • 557 Words
    • 3 Pages

    When it comes to UNIX systems all user data is organized and stored in files. These files are subsequently organized into a management structure comprising of directories and sub-directories. Much like forest and organizational units when it comes to active directory, UNIX also has the directories and sub-directories organized into a tree-like structure that it calls a file system. UNIX also has three basic types of files. When it comes to security files can be secured through UNIX file permissions as well as access control lists (ACLs).…

    • 557 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Fedora 15 chapter 7 & 8

    • 375 Words
    • 2 Pages

    fgrep 'a' find lines containing "a"; the -i option tells it to ignore the case (thus both "A" and "a")…

    • 375 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    A:xinetd(extended Internet daemon) is started in my system rather than inetd (internet service daemon). Both of them are super-server daemon started only under request. Because xinetd is more secure than inetd, more Unix- services now replace inetd with xinetd.…

    • 1015 Words
    • 5 Pages
    Powerful Essays
  • Powerful Essays

    Linux Interview Questions

    • 10428 Words
    • 42 Pages

    1. How do you take a single line of input from the user in a shell script?…

    • 10428 Words
    • 42 Pages
    Powerful Essays
  • Better Essays

    The arp command is an acronym that stands for address resolution protocol. This command allows technicians to easily find the IP address and physical address of the computer that they are currently on. This command is also a good tool to see which computers are online in a network because if there is more than one network interface that uses arp it will display the machines on it as well by typing “arp a-“Additionally the command prompt text gives some variants of the arp command where you can choose what available information can be viewed. This command is flexible and can be typed in a few different ways to obtain different results. If you wanted just the physical address of the computer you would type “arp eth_addr”. Another useful functionality of this command is that if you type “arp if_addr” you can select an internet address to be modified.…

    • 1162 Words
    • 5 Pages
    Better Essays
  • Powerful Essays

    UNIX has many tools at its disposal like line editors, application program interfaces, development environments, libraries, and documentation (Anthes, 2009). This makes UNIX a very powerful system and the best part about it all is it was written on a microcomputer. UNIX is a multitasking, multi user computer operating system. When UNIX was created it was…

    • 1593 Words
    • 7 Pages
    Powerful Essays
  • Satisfactory Essays

    Dos Commands

    • 802 Words
    • 4 Pages

    APPEND Allows programs to open data files in specified directories as if they were in the current directory.…

    • 802 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Unix

    • 789 Words
    • 4 Pages

    "UNIX was the first operating system designed to run on ‘dissimilar ' computers by converting most hardware specific commands in machine language into an independent programming language called ‘C '" . UNIX was the basis of AT&T 's telephone system and the government 's wide area network system. Then it became the basis of communication between engineers and scientists, and eventually the basis of communication for everyone worldwide. It has held this remarkable spot since 1969.…

    • 789 Words
    • 4 Pages
    Good Essays