Do take a look at the Article Using Find to Search Better to have a better understanding of the parameters, especially more than 1 parameter and combining find and exec function
BASH
Running process in the background
I have just started another blog to deal with more specific topics on Linux. Finally wrote one…… It is Running process in the background. The blog mentions 3 tools
Solution 1: Nohup and ampersand
Solution 2: Screen
Solution 3: tmux
chsh -s /bin/tcsh and you (user) don’t exist error
Sometimes, you are a non-root user and you wish to change shell and you have an error
$ chsh -s /bin/tcsh
chsh you (user xxxxxxxxx) don't exist
This error occurs when the userID and Passowrd is using LDAP or Active Directory so there is no local account in the /etc/passwd where it first looks to. I used Centrify where we can configure the Default Shell Environment on AD. But there is a simple workaround if you do not want to bother your system administrator
First check that you have install tcsh. I have it!
$ chsh -l
/bin/bash
/bin/cdax/bash
/bin/cdax/csh
/bin/cdax/ksh
/bin/cdax/rksh
/bin/cdax/sh
/bin/cdax/tcsh
/bin/csh
/bin/ksh
/bin/rksh
/bin/sh
/bin/tcsh
/sbin/nologin
/usr/bin/bash
/usr/bin/cdax/bash
/usr/bin/cdax/dzsh
/usr/bin/cdax/sh
/usr/bin/dzsh
/usr/bin/sh
/usr/sbin/nologin
/usr/bin/tmux
Next Step: Check your current shell
$ echo "$SHELL"
/bin/bash
Step 3: Write a simple .profile file
$ vim ~/.profile
if [ "$SHELL" != "/bin/tcsh" ]
then
export SHELL="/bin/tcsh"
exec /bin/tcsh -l # -l: login shell again
fi
Step 4: In your .bashrc, just add the “source ~/.profile”
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
source ~/.profile
Source the .bashrc again
$ source ~/.bashrc
Sorting ls Output Based on Time and Date
You may want to list the files in a directory based on last modified time and date from the latest to the oldest, you will need to use -t
% ls -lt
drwxr-xr-x 26 root root 4096 Mar 29 13:40 mono
drwxr-xr-x 2 root root 42 Mar 29 13:40 mono-source-libs
lrwxrwxrwx 1 root root 22 Dec 21 12:55 libnss_centrifyda.so.0 -> libnss_centrifyda.so.2
drwxr-xr-x. 2 root root 62 Dec 21 12:54 security
lrwxrwxrwx 1 root root 22 Dec 21 12:54 libnss_centrifydc.so.0 -> libnss_centrifydc.so.2
lrwxrwxrwx 1 root root 28 Dec 21 12:54 libnss_centrify_logonly.so.0 -> libnss_centrify_logonly.so.2
-rwxr-xr-x 1 root root 238560 Nov 17 09:13 libnss_centrifydc.so.2
-rwxr-xr-x 1 root root 140064 Nov 17 09:13 libnss_centrify_logonly.so.2
-rwxr-xr-x 1 root root 159112 Nov 9 02:39 libnss_centrifyda.so.2
drwxr-xr-x 4 root root 40 Jul 25 2021 fastx
drwxr-xr-x. 2 root root 100 Dec 11 2020 modprobe.d
drwxr-xr-x 8 root root 180 Oct 26 2020 rstudio-server
.....
.....
If you want a sorting from the oldest to the latest, you use the -r option
% ls -ltr
.....
.....
-rwxr-xr-x 1 root root 159112 Nov 9 02:39 libnss_centrifyda.so.2
-rwxr-xr-x 1 root root 140064 Nov 17 09:13 libnss_centrify_logonly.so.2
-rwxr-xr-x 1 root root 238560 Nov 17 09:13 libnss_centrifydc.so.2
lrwxrwxrwx 1 root root 28 Dec 21 12:54 libnss_centrify_logonly.so.0 -> libnss_centrify_logonly.so.2
lrwxrwxrwx 1 root root 22 Dec 21 12:54 libnss_centrifydc.so.0 -> libnss_centrifydc.so.2
drwxr-xr-x. 2 root root 62 Dec 21 12:54 security
lrwxrwxrwx 1 root root 22 Dec 21 12:55 libnss_centrifyda.so.0 -> libnss_centrifyda.so.2
drwxr-xr-x 2 root root 42 Mar 29 13:40 mono-source-libs
drwxr-xr-x 26 root root 4096 Mar 29 13:40 mono
Listing 50 biggest files in Recursive Directories.
I have always enjoyed BASH Commands that can reveal more the files and directories we have. I wrote a short write-up Checking Disk Usage within the subfolders but avoid mount-point
I wondered whether if I can capture the top 20 directories that uses the most disk space. There was this document by OpenSource.com that I find helpful 7 Linux command-line tips for saving media file space
1 To Find the 50 biggest files in its recursive directory tree
% find -type f -exec du -Sh {} + | sort -rh | head -n 50
19G ./Downloads/xxxxxx.iso
17G ./Downloads/AI/AI.tar
17G ./Downloads/ISO/xxxx.iso
6.4G ./Ansys/uuuuuuuu.zip
5.3G ./.cache/tracker/meta.db
4.5G ./Downloads/HelloThere_AVX2/tar/E45.tbJ
4.4G ./Documents/EEEEE/EEEEEE_dvd.iso
3.7G ./Downloads/12345/2021/2021.tar
.....
......
Using /proc/$PID/fd to understand where the files are written to.
/proc/$PID/fd provide a symbolic link to the file that the process $PID has open on the file descriptor NUM. One useful gain from this, is that I can use /proc/$PID/fd to understand where the files are written to.
% top

Let’s use Process 66090 (1508.exe)
% cd /proc/66090/fd
% ls -l
lr-x------ 1 user1 user1 64 Feb 15 12:41 0 -> /localhome/user1/scratch/G16c-Mistral909223.hpc-mn1/G16c-Mistral.Input.909223.hpc-mn1
l-wx------ 1 user1 user1 64 Feb 15 12:41 1 -> /localhome/user1/AgMPYH-GSH_4.gjf.Output.909223.hpc-mn1.log
lrwx------ 1 user1 user1 64 Feb 15 12:42 10 -> /localhome/user1/scratch/G16c-Mistral909223.hpc-mn1/Gau-66090.d2e
l-wx------ 1 user1 user1 64 Feb 15 12:41 129 -> /myhome/user1/breezetraces/user1-909223.hpc-mn1-hpc-g8004/tmp/monitor-command-fifo
lr-x------ 1 user1 user1 64 Feb 15 12:41 130 -> /proc/66090/mounts
lrwx------ 1 user1 user1 64 Feb 15 12:41 2 -> /var/spool/pbs/spool/909223.hpc-mn1.ER
lrwx------ 1 user1 user1 64 Feb 15 12:41 3 -> /localhome/user1/scratch/G16c-Mistral909223.hpc-mn1/Gau-66081.inp
lrwx------ 1 user1 user1 64 Feb 15 12:41 4 -> socket:[75030280]
lrwx------ 1 user1 user1 64 Feb 15 12:41 5 -> socket:[75030281]
lrwx------ 1 user1 user1 64 Feb 15 12:42 6 -> /localhome/user1/scratch/G16c-Mistral909223.hpc-mn1/Gau-66090.rwf
lrwx------ 1 user1 user1 64 Feb 15 12:42 7 -> /localhome/user1/AgMPYH-GSH_4.chk
lrwx------ 1 user1 user1 64 Feb 15 12:42 8 -> /localhome/user1/scratch/G16c-Mistral909223.hpc-mn1/Gau-66090.skr
lrwx------ 1 user1 user1 64 Feb 15 12:42 9 -> /localhome/user1/scratch/G16c-Mistral909223.hpc-mn1/Gau-66090.int
You can see for most of the user processes, it is written to /localhome/user1.
Generate UUID for Network Interface for CentOS
UUIDs (Universal Unique Identifier) for network interface card can be generated quite easily using the command “uuidgen”. For example
% uuidgen eth0
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
You can go to /etc/sysconfig/network-sscripts/ifcfg-eth0
.....
.....
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
.....
.....
Truncate Log Files in Linux
If you need to shrink or empty the Log Files on a Linux System, you can use the “truncate” command
% truncate -s 0 logfile
where -s is used to set or adjust the file size
If you need to delete multiple files
% truncate -s /var/log/messages-*
References:
/bin/rm : Argument list too long
I was trying to delete the files in the folder that has more than 90,000. When I delete the files, I had errors
% /bin/rm : Argument list too long
The issue is that there are too many files and rm is not able to clear. To workaround the issues, you can do the following. Make sure you are in the directory where you want to clear the file.
% find . -name '*' | xargs rmfind . -name '*' | xargs rm
References:
Checking Disk Usage within the subfolders but avoid mount-point
If you need to check Usage, but you wish to avoid the mount-point, you can use the command
[root@hpc-hn /]# du -h -x -d 1
48M ./etc
552M ./root
11G ./var
1.1G ./tmp
11G ./usr
0 ./media
0 ./mnt
4.8G ./opt
0 ./srv
0 ./install
0 ./log
0 ./misc
0 ./net
0 ./server_priv
0 ./ProjectSpace
0 ./media1
0 ./media2
28G .
- -h refers to human-readable
- -d refers to depth level. By default, it is 0 which is the same as summarize
- -x skip directories on different file systems