Main Menu

Search

Showing posts with label UNIX Commands. Show all posts
Showing posts with label UNIX Commands. Show all posts

LINUX: Take Backup of Files Using DateTimeStamps In Backup Filename (How To Doc)

Below is the command to take backup of file so that backup file has datetimestamps (Date / Timestamps) in name when the file was backed up.
cp -rp testfile.out testfile.out__$(date +%F'-'%T)

In above command example we are backing up testfile.out. Change this filename to the filename you want to backup. Below is example snippet which shows the backup file created with datetimestamps (highlighted in bold).

-rw-r--r-- 1 root root   0 Sep 28 14:39 testfile.out__2019-09-28-14:39:16
-rw-r--r-- 1 root root   0 Sep 28 14:39 testfile.out

Products to which Article Applies

All UNIX Operating Systems

Linux: "ps" Command To Check Process Details Like Number Of Threads, State, Process Command, Start Time, Uptime, Arguments, CPU & Memory Usage (How To Doc)

Below ps command can be executed to get the details about process like number of threads, state, process command, start time, uptime, arguments, CPU & memory usage.
ps -eo pid,thcount,state,comm,lstart,etime,args,%cpu,%mem,cmd

Below is how to interpret each file.


thcount - thread count
state - process state
command - short description of process whether it is java, apache, httpd etc.
lstart - Exact date and time when the process started. Shown in Day Mon DD HH:MM:SS format
etime - Uptime of the process which is shows in Days, HH, MM and Seconds
etime - Startup arguments of the process.
%cpu - CPU utilized by the process.
%mem - Memory utilized by the process.
cmd - Complete command options of the process.

Below is sample output of java process using above ps command.
7413 215 S java  Tue Jul 30 09:55:46 2019 25-02:18:47 04:57:37 /usr/java/bin/  0.8  4.5 /usr/java/bin/java -Xms200M -Xmx8192M -server -XX:StringTableSize=27001 -XX:PermSize=128m -XX:MaxPermSize=384m -Xss256k -XX:+UseParallelOldGC -XX:SoftRefLRUPolicyMSPerMB=10000 


Products to which Article Applies


All UNIX environments

Additional References


LINUX: How To Capture STRACE Output Into A File? (Troubleshooting Doc)

Below strace command can be used to capture the strace command output into a file.
strace -o /tmp/outfile.out ls

In above command we are capturing strace on "ls" command. We can replace "ls" command with the command or proess against which we are running strace. In above example strace output is being redirected to /tmp/output.out file. The output filename can be changed accordingly.


Products to which Article Applies


All Linux and UNIX environments

Additional References




LINUX: "find" Command To File Large Files Only in Local Root File Systems Excluding NFS Shares (How To Doc)

In Linux and UNIX Environments often times there may be need to clean up local filesystem space as it is full. In environment with NFS shares mounted it can get tricky to just identify the large files inside local file system. Below find command can be used to find the large files only in local file system.


find / -xdev -type f -size +500k -exec ls -lh {} \; | sort -n -r

Above command will search for all files inside only the local non NFS file systems which are over 50kb in size and then sort them by size and display.


Products to which Article Applies

All Linux and UNIX Environments.

LINUX: "find" Command To Find Large Files

In Linux and UNIX Environments often times there may be need to clean up filesystem space as it is full. So you will have to identify the files which are huge in size which needs to be checked and them cleaned. For finding the large files which in the file system below command can be used.


find /tmp -type f -size +50k -exec ls -lh {} \; | sort -n -r

Above command will search for all files inside /tmp which are over 50kb in size and then sort them by size and display.

You can change the /tmp to any directory where you want to search for the large files. In case you want to search inside all the directories / filesystems you can specify /. For e.g. as shown below.


find /-type f -size +50k -exec ls -lh {} \; | sort -n -r


Products to which Article Applies

All Linux and UNIX Environments.