Some Unix Commands
- The tar command:
- To tar all the files with extensions cpp and doc into a tar file
called abc.tar do the following
tar cvzf abc.tar *.cpp *.doc
- To tar all the files and the subdirectories of a directory called
temp into a tar file named abc.tar do the following
tar cvzf abc.tar temp
If you want to put abc.tar in a different directory, proceed abc.tar by
the path of the directory. For example, if you are in directory called
parent and you want to tar a directory called child and call the tar file
abc.tar and put abc.tar in the subdirectory child, type
tar cvzf child/abc.tar child
- To see the table of contents of the tar file abc.tar do the
following:
tar tzf abc.tar
- To untar the file abc.tar, do the following:
tar xvzf abc.tar
- To change the password on Unix, type:
passwd
- To check your quota on Unix, type:
quota -v
- To print using Unix, type:
lpr -Pprintername filename
- To change the ownership of a file/directory called abc to NewOwner,
do the following:
chown NewOwner abc
- To change your "plan" file, type:
pico .plan
- To change your "finger" information, type
chfn
- To create a directory called abc:
mkdir abc
- To remove an empty directory called abc:
rmdir abc
- To remove a directory called abc and all of its contents:
rm -rf abc
- Permissions for the web directory and all of its subdirectories:
711
- Permissions for files on the website:
744
- To find out which groups you belong to, type:
groups
- To find out which groups a user called abc belongs to, type:
groups abc
- To find out who are the members of a group called abc, type
getent group abc
- To append the contents of file2 to file1, type
cat file2 >> file1
- To list all files including hidden files whose names begin with a dot
in the current directory and its subdirectories, and put the list in a file called t.txt,
type:
ls -la * >> t.txt
- To list all files in the current directory and its subdirectories and
sort them by modification date, and put the list in a file called t.txt,
type:
ls -lt * >> t.txt
- To search for a file called abc.txt in the current directory and all
of its subdirectories, type
find -name 'abc.txt'
- To search for a file whose name contains the substring abc in the
current directory and all of its subdirectories, type
find -name '*abc*'
- To search for a file whose size is greater than 300k in in the
current directory and all of its subdirectories, type
find -name '*' -size +300k
- To search for a file called abc.txt in the root and all
of its subdirectories, type
find / -name 'abc.txt'