Step by Step Guides Below

Step by step guides below.

Remove file from or delete file from Fedora system.

[root@fedora /]# rm install.log
rm: remove regular file `install.log’? y
The command above remove/delete the file called “install.log”. Use ls command to confirm the removal/deletion.
How to remove or delete several file?
Remove more that one file in one time.
[root@fedora /]# rm install.log kambing.log secure1.log config.doc passwd
rm: remove regular empty file `install.log’? y
rm: remove regular empty file `kambing.log’? y
rm: remove regular empty file `secure1.log’? y
rm: remove regular empty file `config.doc’? y
rm: remove regular empty file `passwd’? y
rm command also can be used to remove or delete the several file at once, in this example five files ( install.log, kambing.log, secure1.log, config.doc, passwd ) is deleted at one go.
How to remove or delete files that use metacharacter (character that mean something to the shell) as file name?
If you have file or folder name that use metacharacter or characters that mean something to shell, you have to tell the shell prompt so that the shell could interpreted that you want to remove files. Below is some example to remove the metacharacter files:
[root@fedora /]# rm -r ./*important-file*
rm: remove directory `./*important-file*’? y
[root@fedora /]# rm — -not-important*
rm: remove regular file `-not-important*’? y
[root@fedora /]# rm ‘happy rock hacking.mp3′
rm: remove regular file `happy rock hacking.mp3’? y
To remove/delete the file that contains a space or character which is used by the shell, in this example;
*important-file* The filename contain ( * )
-not-important* The filename contain ( – ) in the beginning and ( * )
happy rock hacking.mp3 The file name use space
Put a single quotes around them or force it using the current directory sign ( ./ ) or used rm — option.
How to remove or delete all files in current directory?
The example below show the rm command use to delete all file in the current directory.
[root@linux hack]# rm ./*
rm: remove regular file `./install.log.syslog’? y
rm: remove regular file `./#interface#’? y
rm: remove regular file `./izes in human readable format (e.g., 1K 234M 2G)’? y
The rm command above will remove or delete all file except the hidden files in that current directory.
How to remove or delete a directory?
To remove the directory just issue the rm command with the directory name, if the directory is not empty you may get the same massage bellow:
[root@fedora /]# rm fedora/
rm: cannot remove directory `fedora/': Is a directory
If you know that the directory that you want delete (remove) is not empty and you are sure that you want to remove the directory and all of its contents; issue the rmcommand with the -r option:
[root@fedora /]# rm -r fedora/
rm: descend into directory `fedora/’? y
rm: remove regular empty file `fedora//passwd.kambing’? y
rm: remove regular empty file `fedora//.exploits’? y
rm: remove regular empty file `fedora//.labu’? y
rm: remove regular empty file `fedora//passwd.log’? y
rm: remove regular empty file `fedora//kambing.log’? y
rm: remove regular empty file `fedora//secure1.log’? y
rm: remove regular empty file `fedora//.SELinux’? y
rm: remove regular empty file `fedora//install.log’? y
rm: remove regular empty file `fedora//config.doc’? y
rm: remove directory `fedora/’? y
The rm command above with –r (recursive) option is to remove or delete the fedora directory and all files and directory that contain in the directory that you want to remove.
How to remove or delete everything in current directory without warning?
Remove all files without any warning from the system ( no message output to the screen).
[root@fedora ~]# rm –rf *
[root@fedora ~]# rm –rf ./*
The rm command above with –rf (recursively and remove or delete write-protected file without prompting) option will remove or delete everything in the current directory without any warning.
WARNING : “rm –rf *’ command will remove or / delete everything in current directory except hidden file or directory in that current directory. Make sure that you not in the root directory ( / ) before you issue the command or you could end up with empty and broken Linux box. Be careful, rm command can be a dangerous tool if misused.
How to remove or delete all hidden file or directory without warning?
Remove all file and directory without any output to the screen,
[root@fedora /]# rm –rf .??*
With the option –rf and the use ” .??* ” will remove/delete all hidden files/directory. The initial ” . ” indicates a ‘hidden’ file and the ” ?? ” match at least two characters to exclude the parent-directory which is ” .. ” and to remove or delete everything the ” * ” will match all number or characters that used for files or directory name.
How to remove or delete file base on (use) its inode / index number?
The example below show the step to delete or remove the file base on the inode number.
Issue the ls command with the -i option to get the inode number for the file.
[root@fedora /]# ls -i
245242 sysdetails.txt
245243 tat – display file or filesystem status
976527 test
245274 timate file space usage
245275 uptime.txt
245276 ystem disk space usage
Using the find command to find inode number for the file and then pass to the rm command to delete the file base on their inode number.
[root@fedora /]# find . -inum 245243 -exec rm –i {} \;
rm: remove regular file `./tat – display file or filesystem status’? y
Verify to make sure that the file have been remove by using ls command.
[root@fedora /]# ls
timate file space usage
ystem disk space usage
From the example above, the ‘ls –i’ command is used to get the inode number of file or directory then the find command used to search for inode number “245243” then give the inode number to rm command to remove or delete the file base on the inode number given..
The following are some of the flags and arguments that can be used with the rm command:
Remove (unlink) the FILE(s).
-d, –directory unlink FILE, even if it is a non-empty directory
(super-user only; this works only if your system
supports `unlink’ for nonempty directories)
-f, –force ignore nonexistent files, never prompt
-i, –interactive prompt before any removal
–no-preserve-root do not treat `/’ specially (the default)
–preserve-root fail to operate recursively on `/’
-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
Note: if you use rm to remove a file, it is possible to recover the contents of that file. If you want more assurance that the contents are truly unrecoverable, consider using shred.
Note:- On Fedora Core using bash shell, the rm command is alias to rm=’rm -i’. The rm is the command to remove files or folder in Linux system but there is no unrm orundelete or unremove command on Linux operating system. So be very careful on what you wish to remove :-)
Warning: The rm command can do many harm thing to your system, make sure that you double check before executing the rm command.
stat – display file or filesystem status
Usage: rm [OPTION]… FILE…
Need help or need more information use:
# info rm
# man rm
# rm –help



Linux remove or clear the last login information


How do I clear or remove last login information? I would like to clear all the login information. I am using Fedora Core 6 Linux.
A. /var/log/lastlog file stores user last login information. This is binary file. You need to use lastlog command to formats and prints the contents of the last login log /var/log/lastlog file.
Following information is printed using lastlog command:
=> The login-name
=> Port
=> Last login time
Task: Display last login information
Simply type lastlog:
$ lastlog
Username         Port     From             Latest
root             tty1                      Thu Jan 25 15:23:50 +0530 2007
daemon                                     **Never logged in**
bin                                        **Never logged in**
sys                                        **Never logged in**
sync                                       **Never logged in**
vivek            tty1                      Sat Jan 27 22:10:36 +0530 2007
pdnsd                                      **Never logged in**
sshd                                       **Never logged in**
messagebus                                 **Never logged in**
bind                                       **Never logged in**
sweta           tty1                      Sat Jan 27 19:55:22 +0530 2007
Note: If the user has never logged in the message “**Never logged in**” will be displayed instead of the port and time.
Task: Clear last login information
Simply overwrite /var/log/lastlog file. You must be the root user. First make a backup of /var/log/lastlog:
# cp /var/log/lastlog /root
Now overwrite file using any one of the following command:
# >/var/log/lastlog
# cat > /var/log/lastlog



How do I rotate log files under Linux operating system?


A. You need use tool called logrotate, which is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files.
Each log file may be handled daily, weekly, monthly, or when it grows too large. With this tool you keep logs longer with less disk space.
Default configuration file
The default configuration file is /etc/logrotate.conf:
# see “man logrotate” for details
# rotate log files weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
# uncomment this if you want your log files compressed
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp — we’ll rotate them here
/var/log/wtmp {
create 0664 root utmp
rotate 1
}Service or server specific configurations stored in /etc/logrotate.d directory, for example here is sample apache logrotate configuration file:# cat /etc/logrotate.d/httpdOutput:
/var/log/httpd/*.log {
rotate 52
/bin/kill -HUP `cat /var/run/ 2>/dev/null` 2> /dev/null || true    endscript
• weekly : Log files are rotated if the current weekday is less then the weekday of the last rotation or if more then a week has passed since the last rotation.
• rotate 52 : Log files are rotated 52 times before being removed or mailed to the address specified in a mail directive. If count is 0, old versions are removed rather then rotated.
• compress : Old versions of log files are compressed with gzip to save disk space.
• missingok : If the log file is missing, go on to the next one without issuing an error message.
• notifempty : Do not rotate the log if it is empty
• sharedscripts : Normally, prerotate and postrotate scripts are run for each log which is rotated, meaning that a single script may be run multiple times for log file entries which match multiple files. If sharedscript is specified, the scripts are only run once, no matter how many logs match the wildcarded pattern. However, if none of the logs in the pattern require rotating, the scripts will not be run at all.
• postrotate
/bin/kill -HUP `cat /var/run/ 2>/dev/null` 2> /dev/null || true
endscript : The lines between postrotate and endscript (both of which must appear on lines by themselves) are executed after the log file is rotated. These directives may only appear inside a log file definition.