11:00 - 17:00

Mon - Fri

Unix Commands Documentation

Command Options Remarks Example
ln - Hard Link. Two files can have the same inode number, permissions, and timestamp. Both files should be on the same file system. Changes made to one file are automatically available in the other. The count of hard links is shown in `ls`. ln origfile linkedfile
ln -s Soft Link. It can be across two file systems. It's also used to link directories. It's just a directory entry containing the pathname. It has "l" in the permission field. The inode of both files is different. ln -s orgfile linkedfile
find -name Search based on filename. find searchpath -name "file search criteria"
ls -a List file contents including hidden files. ls -a
ls -F Lists file contents, marks executable as *, directory as /, and soft link as @. ls -F
chmod - To grant rights to a file. Read permission=4, Write permission=2, and Execute permission=1. Even with 777 rights, only the owner can delete the file while others can edit it. chmod 756 gives all permission to the user, read and write access to the group, and read and execute permissions to other users
umask - Default permissions for file are 666 and directories 777. Of this, umask is subtracted to get default permissions. If umask is 022 then default permission for file will be 644 and directory will be 755.
cp -p Copies file and preserves a file's attributes. cp -p sourcefile destinationfile
grep -i Case-insensitive search. grep -i "search_term" filename
grep -r Recursive search through directories. grep -r "search_term" directory
tar -cvf Create a tarball archive. tar -cvf archive.tar directory
tar -xvf Extract a tarball archive. tar -xvf archive.tar
ps -aux Display information about all processes. ps -aux
kill -9 Force kill a process. kill -9 PID
df -h Display disk space usage in human-readable format. df -h
du -sh Display directory size in human-readable format. du -sh directory
echo -e Enable interpretation of backslash escapes. echo -e "Line1\nLine2"
history - Display command history. history
man - Display the manual for a command. man ls
sudo - Execute a command with superuser privileges. sudo command
wget -O Download files from the web. wget -O filename URL
curl -O Transfer data from or to a server. curl -O URL
nano - Text editor for command line. nano filename
vim - Advanced text editor. vim filename
top - Display real-time system processes. top
uptime - Show how long the system has been running. uptime
date - Display or set the system date and time. date
Command List with Options and Remarks
-------------------------------------
ln
- Hard Link. Two files can have the same inode number, permissions, and timestamp.
Both files should be on the same file system. Changes made to one file are automatically available in the other.
If one file is deleted, the other file is still available. The count of hard links is shown in ls.
Example: ln origfile linkedfile
-s: Soft Link. Can be across two file systems. Used to link directories. It's just a directory entry containing the pathname.
It has 'l' in the permission field. The inode of both files is different.
Example: ln -s origfile linkedfile
find
-name: Search based on filename.
Example: find searchpath -name 'file search criteria'
-type: Search for file types (f for file, d for directory, l for link).
Example: find -type d
-perm: Search based on file permissions in integer format.
Example: find . -perm 666 or find . -perm 400
-inum: Search based on inode number.
Example: find . -inum 3455
-samefile: Search all hard links for the file.
Example: find . -samefile file1
-links: Show files with n number of links.
Example: find . -links +2
-user: Search based on user.
-size: Search based on file size.
Example: find . -size +x
-mtime: Search based on modified time.
Example: find . -mtime +2 -mtime -5
-ctime: Search based on create time.
Example: find . -ctime +2 -ctime -5
-atime: Search based on accessed time.
Example: find . -atime +2 -atime -5
-follow: Follow symbolic links.
Example: find . -name '*.eps' -follow
-exec: Execute an action on the found files.
Example: find . -name '*.eps' -exec rm -f {} \;
-ok: Execute an action on the found files in interactive mode.
Example: find . -name '*.eps' -ok rm -f {} \;
-print: Print selected files to the terminal.
Example: find . -name '*.eps' -print
-ls: Print complete details and path of the files found.
Example: find . -name '*.eps' -ls
-a: AND condition.
-o: OR condition.
Example: find . -name '*7710916*' -o -name '*7710909*'
!: NOT condition.
ls
-a: List all files, including hidden files.
-F: List files with special characters marking file types.
Example: ls -F
-R: List directory contents recursively.
Example: ls -R
-d: List directory entries, not their contents.
Example: ls -d
-l: Long listing format.
Example: ls -l
-n: Numeric user and group IDs.
Example: ls -n
-t: Sort by modification time.
Example: ls -t
-ltr: Sort by modification time, newest first.
Example: ls -ltr
-lt: Sort by modification time, newest first.
Example: ls -lt
-u: Sort by last access time.
Example: ls -u
-i: List inode numbers.
Example: ls -i
chmod
- Grant rights to a file. Read permission = 4, Write permission = 2, Execute permission = 1.
Example: chmod 756 gives all permissions to the user, read and write access to the group, and read and execute permissions to others.
-R: Apply permissions recursively.
Example: chmod -R 755 directory/
umask
- Default permissions are 666 for files and 777 for directories. Umask is subtracted from these defaults.
Example: If umask is 022, the default permission for files will be 644 and for directories 755.
cp
-p: Preserve file attributes while copying.
Example: cp -p sourcefile destinationfile
chown
- Change ownership of a file.
Example: chown new_owner filename
-R: Change ownership recursively.
Example: chown -R newowner directory/
chgrp
- Change group ownership of a file.
Example: chgrp newgroup filename
-R: Change group ownership recursively.
Example: chgrp -R newgroup directory/
-f: Forcefully change the group of a file.
-h: Change the group of the symbolic link itself, not the file it points to.
touch
- Create a dummy file.
-m: Change only the modification time.
-a: Change only the access time.
echo
*: List contents of the current directory unformatted.
\*: Escape character to ignore the next character.
Example: rm file\* will delete file1, file2, etc.
Wild Cards
[a-zA-Z0-9]: Matches files with a specific pattern.
Example: ls file[a-zA-Z0-9]
[!x-z]: Matches files not ending with x, y, or z.
Example: ls file[!x-z]
Escape Characters
\n: New line.
Example: echo 'first line\nsecond line'
\t: Tab.
Example: echo '\t tabbed'
\c: Suppress trailing newline.
Example: echo 'no newline\c'
\g or \007: Bell character (beep).
Example: echo 'beep\g'
more
- View file contents page by page. Use space to scroll, /searchcondition for search.
wc
-l: Count number of lines.
-w: Count number of words.
-c: Count number of characters.
pr
- Prepare file for printing with headers, footers, and formatted text.
-l: Change default page length.
echo 2553138
- Returns PID of the current shell/terminal.
cmp
- Compare two files, returning line number of first difference.
-l: Compare byte by byte.
Example: cmp -l file1 file2
diff
- Compare two files and return differences to make them identical.
comm
- Compare two files and return records unique to each file and common records.
Example: comm file1 file2
-1: Suppress first column.
-2: Suppress second column.
-3: Suppress third column.
head
- Display the first 10 lines of a file. Use -n to specify a different number of lines.
Example: head -n 20 file
tail
- Display the last 10 lines of a file.
-f: Follow the file, displaying new lines as they are added.
Example: tail -f file
+100: Display lines after line 100.
cut
-c: Cut by character position.
Example: cut -c 1-3,5-10 file
-d: Define delimiter.
-f: Cut by field based on delimiter.
Example: cut -d: -f2-4 file
paste
-d: Concatenate files with a specific delimiter.
Example: paste -d: file1 file2
sort
- Sort lines in a file.
-r: Reverse order.
-n: Numerical sort.
-k: Sort based on key.
Example: sort -k2,2 -n file
uniq
- Remove duplicate lines.
-c: Count occurrences of each line.
Example: uniq -c file
tr
- Translate or delete characters.
-d: Delete characters.
-s: Squeeze repetitions.
Example: tr 'a-z' 'A-Z' < file
tee
- Read from standard input and write to both standard output and files.
Example: command | tee file
xargs
- Build and execute command lines from input.
Example: find . -name '*.txt' | xargs wc -l
-------------------------------------
End of Command List