These are the numeric values and its related permissions in a linux system.
4000 - Setuid on execution
2000 - setgid on execution
1000 - set sticky bit
0400 - read by owner
0200 - write by owner
0100 - execute by owner
0040 - read by group
0020 - wrrite by group
0010 - execute by group
0004 - read by others
0002 - write by others
0001 - execute by others
The chmod numeric value varies from 0000 to 7777
You can use these or combination of these numeric values with chmod command or you can specify it with strings. While specifying with strings use the following arguments..
u - user - to add/remove permissions of user or owner of file.
g - group - to add/remove permissions of group members of file.
o - other - to add/remove permissions of other group members or world wide permission of file.
Eg:
The following commands will enable the setuid on the file abc.pl
chmod 4755 abc.pl
chmod u+s abc.pl
December 19, 2009
Locating files using the find command
Find is a versatile tool which can be used to locate files and directories satisfying different user criteria. But the sheer number of options for this command line tool makes it at the same time both powerful and encumbering for the user. Here I will list a few combinations which one can use to get useful results using find command.
Find all HTML files starting with letter 'a' in your current directory (Case sensitive)
find . -name a\*.html
Same as above but case insensitive search.
find . -iname a\*.html
Find files which are larger than 5 MB in size.
find . -size +5000k -type f
Here the '+' in '+5000k' indicates greater than and k is kilobytes. And the dot '.' indicates the current directory. The -type option can take any of the following values:
f - file
d - directory
l - symbolic link
c - character
p - named pipe (FIFO)
s - socket
b - block device
Find all empty files in your directory
find . -size 0c -type f
... Which is all files with 0 bytes size. The option -size can take the following:
c - bytes
w - 2 byte words
k - kilo bytes
b - 512 byte blocks
Note: The above command can also take the -empty parameter.
Find is very powerful in that you can combine it with other commands. For example, to find all empty files in the current directory and delete them, do the following:
find . -empty -maxdepth 1 -exec rm {} \;
To search for a html file having the text 'Web sites' in it, you can combine find with grep as follows:
find . -type f -iname \*.html -exec grep -s "Web sites" {} \;
... the -s option in grep suppresses errors about non-existent or unreadable files. And {} is a placeholder for the files found. The semicolon ';' is escaped using backslash so as not to be interpreted by bash shell.
Note: You can use the -exec option to combine any command in Linux with the find command. Some of the useful things you can do with it are as follows:
Compress log files on an individual basis
find /var -iname \*.log -exec bzip {} \;
Find all files which belong to user lal and change its ownership to ravi
find / -user lal -exec chown ravi {} \;
Note: You can also use xargs command instead of the -exec option as follows:
find /var -iname \*.log | xargs bzip -
Find all files which do not belong to any user:
find . -nouser
Find files which have permissions rwx for user and rw for group and others :
find . -perm 766
... and then list them.
find . -perm 766 -exec ls -l {} \;
Find all directories with name music_files
find . -type d -iname \*music_files\*
Suppose you want to find files of size between 700k and 1000k, do the following:
find . \( -size +700k -and -size -1000k \)
And how about getting a formatted output of the above command with the size of each file listed ?
find . \( -size +700k -and -size -1000k \) -exec du -Hs {} \; 2>/dev/null
... here, the '2>/dev/null' means all the error messages are discarded or suppressed.
You can also limit your search by file system type. For example, to restrict search to files residing only in the NTFS and VFAT filesystem, do the following:
find / -maxdepth 2 \( -fstype vfat -or -fstype ntfs \) 2> /dev/null
These are the most common uses of the find command. You can see additional uses by reading the find manual.
Find all HTML files starting with letter 'a' in your current directory (Case sensitive)
find . -name a\*.html
Same as above but case insensitive search.
find . -iname a\*.html
Find files which are larger than 5 MB in size.
find . -size +5000k -type f
Here the '+' in '+5000k' indicates greater than and k is kilobytes. And the dot '.' indicates the current directory. The -type option can take any of the following values:
f - file
d - directory
l - symbolic link
c - character
p - named pipe (FIFO)
s - socket
b - block device
Find all empty files in your directory
find . -size 0c -type f
... Which is all files with 0 bytes size. The option -size can take the following:
c - bytes
w - 2 byte words
k - kilo bytes
b - 512 byte blocks
Note: The above command can also take the -empty parameter.
Find is very powerful in that you can combine it with other commands. For example, to find all empty files in the current directory and delete them, do the following:
find . -empty -maxdepth 1 -exec rm {} \;
To search for a html file having the text 'Web sites' in it, you can combine find with grep as follows:
find . -type f -iname \*.html -exec grep -s "Web sites" {} \;
... the -s option in grep suppresses errors about non-existent or unreadable files. And {} is a placeholder for the files found. The semicolon ';' is escaped using backslash so as not to be interpreted by bash shell.
Note: You can use the -exec option to combine any command in Linux with the find command. Some of the useful things you can do with it are as follows:
Compress log files on an individual basis
find /var -iname \*.log -exec bzip {} \;
Find all files which belong to user lal and change its ownership to ravi
find / -user lal -exec chown ravi {} \;
Note: You can also use xargs command instead of the -exec option as follows:
find /var -iname \*.log | xargs bzip -
Find all files which do not belong to any user:
find . -nouser
Find files which have permissions rwx for user and rw for group and others :
find . -perm 766
... and then list them.
find . -perm 766 -exec ls -l {} \;
Find all directories with name music_files
find . -type d -iname \*music_files\*
Suppose you want to find files of size between 700k and 1000k, do the following:
find . \( -size +700k -and -size -1000k \)
And how about getting a formatted output of the above command with the size of each file listed ?
find . \( -size +700k -and -size -1000k \) -exec du -Hs {} \; 2>/dev/null
... here, the '2>/dev/null' means all the error messages are discarded or suppressed.
You can also limit your search by file system type. For example, to restrict search to files residing only in the NTFS and VFAT filesystem, do the following:
find / -maxdepth 2 \( -fstype vfat -or -fstype ntfs \) 2> /dev/null
These are the most common uses of the find command. You can see additional uses by reading the find manual.
Simple linux commands
/bin/ls Lists the contents of the directory.
/bin/cp Copies the file.
/bin/mv Moves the file.
/bin/rm Deletes the file.
/bin/vi A very versatile, flexible and powerful editor.
/bin/touch Update the time stamp of the file with current time.
/bin/df Shows the disk free space of mounted file systems.
/usr/bin/du Shows the disk usage.
/usr/bin/who Displays who's loged in the system.
/bin/cat Concatenate files and print the output on the standard output.
/bin/cp Copies the file.
/bin/mv Moves the file.
/bin/rm Deletes the file.
/bin/vi A very versatile, flexible and powerful editor.
/bin/touch Update the time stamp of the file with current time.
/bin/df Shows the disk free space of mounted file systems.
/usr/bin/du Shows the disk usage.
/usr/bin/who Displays who's loged in the system.
/bin/cat Concatenate files and print the output on the standard output.
How to use RPM Commands
This section contains an overview of principal modes using with RPM for installing, uninstalling, upgrading, querying, listing, and checking RPM packages on your Linux system. You must be familiar with these RPM commands now because we'll use them often in the continuation of this book. To install a RPM package, use the command:
[root@deep] /#rpm -ivh foo-1.0-2.i386.rpm
Take a note that RPM packages have a file of names like foo-1.0-2.i386.rpm, which include the package name (foo), version (1.0), release (2), and architecture (i386).
To uninstall a RPM package, use the command:
[root@deep] /#rpm -e foo
Notice that we used the package name foo, not the name of the original package file foo-1.0-2.i386.rpm.
To upgrade a RPM package, use the command:
[root@deep] /#rpm -Uvh foo-1.0-2.i386.rpm
With this command, RPM automatically uninstall the old version of foo package and install the new one. Always use rpm -Uvh to install packages, since it works fine even when there are no previous versions of the package installed.
To query a RPM package, use the command:
[root@deep] /#rpm -q foo
This command will print the package name, version, and release number of installed package foo. Use this command to verify that a package is or is not installed on your system.
To display package information, use the command:
[root@deep] /#rpm -qi foo
This command display package information; includes name, version, and description of the installed program. Use this command to get information about the installed package.
To list files in package, use the command:
[root@deep] /#rpm -qlfoo
This command will list all files in a installed RPM package. It works only when the package is already installed on your system.
To check a RPM signature package, use the command:
[root@deep] /#rpm --checksig foo
This command checks the PGP signature of specified package to ensure its integrity and origin. Always use this command first before installing new RPM package on your system. Also, GnuPG or Pgp software must be already installed on your system before you can use this command.
Look at the scripts/config files and documentation that ship with the package, you can do that using:
[root@deep] /#rpm -qc
resp.
[root@deep] /#rpm -qd
In most cases a solution may be at hand without needing my help.
[root@deep] /#rpm -ivh foo-1.0-2.i386.rpm
Take a note that RPM packages have a file of names like foo-1.0-2.i386.rpm, which include the package name (foo), version (1.0), release (2), and architecture (i386).
To uninstall a RPM package, use the command:
[root@deep] /#rpm -e foo
Notice that we used the package name foo, not the name of the original package file foo-1.0-2.i386.rpm.
To upgrade a RPM package, use the command:
[root@deep] /#rpm -Uvh foo-1.0-2.i386.rpm
With this command, RPM automatically uninstall the old version of foo package and install the new one. Always use rpm -Uvh to install packages, since it works fine even when there are no previous versions of the package installed.
To query a RPM package, use the command:
[root@deep] /#rpm -q foo
This command will print the package name, version, and release number of installed package foo. Use this command to verify that a package is or is not installed on your system.
To display package information, use the command:
[root@deep] /#rpm -qi foo
This command display package information; includes name, version, and description of the installed program. Use this command to get information about the installed package.
To list files in package, use the command:
[root@deep] /#rpm -qlfoo
This command will list all files in a installed RPM package. It works only when the package is already installed on your system.
To check a RPM signature package, use the command:
[root@deep] /#rpm --checksig foo
This command checks the PGP signature of specified package to ensure its integrity and origin. Always use this command first before installing new RPM package on your system. Also, GnuPG or Pgp software must be already installed on your system before you can use this command.
Look at the scripts/config files and documentation that ship with the package, you can do that using:
[root@deep] /#rpm -qc
resp.
[root@deep] /#rpm -qd
In most cases a solution may be at hand without needing my help.
Difference Between .rpm and .tar.gz
RPM
Rpm (redhat package manager), is default installation type for all distributions except debian (which use .deb's).
The main uses are
Install from compiled i386|i486|i586|i686.rpm
rpm -ivh applicationname.i386.rpm
this breaks down to -i (install) -v (be verbose) h (hash -- or show progress)
Upgrading comes in the form of
rpm -Uvh appname.i386.rpm
(-U being upgrade)
Rebuilding from a .src.rpm
rpm --rebuild appname.src.rpm
Here the configure and make script are performed automagically. A couple of lines up when the compilation is finished it will say
WROTE: /usr/src/RPM/RPMS/i686/appname.rpm
or something similar. All you need to do then is
rpm -ivh (or Uvh) /usr/src/RPM/RPMS/i686/appname.rpm
Source tar.gz
Most source applications come in tar.gz files. These are compressed files not unlike .zip files. These are uncompressed using
tar xzvf tarfilename.tar.gz
x = extract, z = gzip, v = verbose f=file/force
The sources should now be untarred to their own directory from where you unpacked them.
cd newappdir
(change directory)
run the configure script
./configure
if all goes well, with no errors the make files are now created. Now we run
make
Once all the source files are compiled, the app is installed
make install
The app can now be located in the same dir, or optionally in /usr/bin or /usr/sbin
Rpm (redhat package manager), is default installation type for all distributions except debian (which use .deb's).
The main uses are
Install from compiled i386|i486|i586|i686.rpm
rpm -ivh applicationname.i386.rpm
this breaks down to -i (install) -v (be verbose) h (hash -- or show progress)
Upgrading comes in the form of
rpm -Uvh appname.i386.rpm
(-U being upgrade)
Rebuilding from a .src.rpm
rpm --rebuild appname.src.rpm
Here the configure and make script are performed automagically. A couple of lines up when the compilation is finished it will say
WROTE: /usr/src/RPM/RPMS/i686/appname.rpm
or something similar. All you need to do then is
rpm -ivh (or Uvh) /usr/src/RPM/RPMS/i686/appname.rpm
Source tar.gz
Most source applications come in tar.gz files. These are compressed files not unlike .zip files. These are uncompressed using
tar xzvf tarfilename.tar.gz
x = extract, z = gzip, v = verbose f=file/force
The sources should now be untarred to their own directory from where you unpacked them.
cd newappdir
(change directory)
run the configure script
./configure
if all goes well, with no errors the make files are now created. Now we run
make
Once all the source files are compiled, the app is installed
make install
The app can now be located in the same dir, or optionally in /usr/bin or /usr/sbin
How to delete symbolic link
When using the rm or unlink command to remove a symbolic link to a directory, make sure you don’t end the target with a ‘/’ character because it will create an error. Example:
$ mkdir dirfoo
$ ln -s dirfoo lnfoo
$ rm lnfoo/
rm cannot remove directory ‘lnfoo/’ : Is a directory
$ unlink lnfoo/
unlink: cannot unlink ‘lnfoo/’: Not a directory
$ unlink lnfoo
$ mkdir dirfoo
$ ln -s dirfoo lnfoo
$ rm lnfoo/
rm cannot remove directory ‘lnfoo/’ : Is a directory
$ unlink lnfoo/
unlink: cannot unlink ‘lnfoo/’: Not a directory
$ unlink lnfoo
scp - Secure copy of your content
scp is a great way to move files around from one machine to second machine.
This can take the place of an ftp server for moving files around.
From remote machine to local
root :~# scp user@xx.xx.xx.xx:/home/user/old-stuff /home/user/restore
From local machine to remote
root :~# scp home/to/file you@xx.xx.xx.xx:path/to/file
From remote to remote
root :~# scp user@xx.xx.xx.xx:path/to/file user@xx.xx.xx.xx:path/to/file
xx.xx.xx.xx == Your server IP
This can take the place of an ftp server for moving files around.
From remote machine to local
root :~# scp user@xx.xx.xx.xx:/home/user/old-stuff /home/user/restore
From local machine to remote
root :~# scp home/to/file you@xx.xx.xx.xx:path/to/file
From remote to remote
root :~# scp user@xx.xx.xx.xx:path/to/file user@xx.xx.xx.xx:path/to/file
xx.xx.xx.xx == Your server IP
Subscribe to:
Posts (Atom)