• How to report the complete version of the installed rpm on a LINUX machine?
    Post By: admin

Execute the following command to report the complete version of the installed rpm:

rpm -qa --queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH}) "

  • I have more than a million files in a directory on my linux system. I am trying to move the files using the conventional mv commands but command exits with error 'Too Many Arguments'. How can I move these files successfully?
    Post By: admin

It is bit tricky when there are so many files in a directory on UNIX/LINUX system and getting 'Too Many Arguments' is expected. There are different ways to move files to another location rather than directly using the mv command. You can try the following commands:

find source-directory -type f -name *.* -maxdepth 1 -exec mv {} target-directory/ \;

The above command will find all files from the source-directory and then move them into target-directory.

The other quick way to find and move the files is first redirect the output of find command to a shell script then split the shell script and execute the scripts in parallel as shown below

find source-directory -type f -name *.* -maxdepth 1 -exec echo mv {} target-directory/ \; > move-script.sh

In above command we are redirecting the output of find command along with the actual mv command syntax into a move-script.sh shell script. lets suppose we have million files in source-directory hence move-script will have a million rows and we split the move-script.sh further so that each script will have 200000 rows in it.

split -l 200000 move-script.sh

The split command will split the move-script.sh in number of files containing 200000 rows in it and the default names for the split files may be xaa, xab, xac etc. Now give these split files execute permission and execute them with nohup as shown below:

nohup xaa > xaa.log 2>&1
nohup xab > xab.log 2>&1 
etc

 

  • How to list top 10 largest file in the current working directory on a Linux/Unix system?
    Post By: admin

find . -ls | sort -nrk 7 | head -10

  • How to delete files in a particular directory that are older than 15 days?
    Post By: admin

Execute the following command:

find /yourDir -group groupName -type f -mtime +15 -exec rm -f {} \;

  • How to delete the trailing whitespaces at the end of each line using vi or vim in LINUX/UNIX?
    Post By: admin

Use following command in the editor:

:%s/\s\+$//