- RHEL 7
usermod -G "" user
find / -group 2000 -exec chgrp -h foo {} \;
find /var/log -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
/var/log/messages.1: 5G
/var/log/messages: 4G
find folder/ -type f -name "*.bat" -exec rm -f {} \;
find folder/ -maxdepth 1 -type f -user <user> -print0 | xargs -0 ls -l
find . -type f -name "*bar*" | xargs -n 1 /usr/bin/perl -e '($new=$ARGV[0]) =~ s/bar/foo/; system(qq(mv),qq(-v), $ARGV[0], $new);'
find . \! -user foo -print
will exclude: ./misc
find . -path ./misc -prune -o -name '*.txt' -print
will exclude: dir1 dir2 dir3
find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print
(how-to-exclude-a-directory-in-find-command) [https://stackoverflow.com/questions/4210042/how-to-exclude-a-directory-in-find-command]
find . -printf "%m:%f\n"
650:.
du -hsx * | sort -rh | head -10
sudo du -hx --max-depth=1 /var
4.0K /var/nis
82M /var/spool
...
cat /dev/null > logfile
How to clean log files (http://unix.stackexchange.com/questions/92384/how-to-clean-log-file)
.
..
example1
example2
example3
tar --exclude="./example1" --exclude="./example2" --exclude="backup_example.tar.gz" -cvzf backup_example.tar.gz .
will appear as
tar -tvzf backup_example.tar.gz .
.
..
example3
tar -cvzf archive.tar.gz -C /home/user/some_folder .
will create:
./archive.tar.gz
To input compressed package to another directory, just define where (e.g /var/www/{compressed_package}.tar.gz)
tar -cvzf /var/www/backup_example.tar.gz some_folder_or_file
compressed package will appear in:
/var/www/
we have backup_example.tar.gz with this structure
.
..
/root
|
-/folder1
-/folder2
tar -xvzf backup_example.tar.gz --strip 1
will untar as
/folder1
/folder2
tar -xzvf backup_example.tar.gz -C /var/www
compressed package will be unpacked to:
/var/www/
zip -r directory.zip directory
Let's have some zip archive:
|example.zip
|-folder1
|-folder2
unzip example.zip -x "folder1/*" -d example_unziped
Output:
|example_unziped
|-folder2
works also with wildcards
|example.zip
|-folder1a
|-folder2
|-folder3a
unzip example.zip -x "folder*a/*" -d example_unziped
Output:
|example_unziped
|-folder2
Let's have some zip archive:
|example.zip
|-folder1
|-folder2
unzip example.zip "folder1/*" -d example_unziped
Output:
|example_unziped
|-folder1
a.zip
b.zip
c.zip
$ unzip '*zip'
Archive: c.zip
creating: c/
inflating: c/test.txt
Archive: a.zip
creating: a/
inflating: a/test.txt
Archive: b.zip
creating: b/
inflating: b/test.txt
3 archives were successfully processed.
crontab -l > cron.bak
crontab cron.bak
chown -vh user:group symbolic_link
do not include /, like symbolic_link/ , use plain symbolic_link
Change symbolic link ownership
ps -o etime= -p "$$"
where:
$$ - PID of process
etime= - Skip header
return format: [[dd-]hh:]mm:ss
how-to-check-how-long-a-process-has-been-running
curl -u username:password http://location/*.html
curl -u username:password http://location/*.html | grep "<a href=" | sed "s/<a href/\\n<a href/g" | sed 's/\"/\"><\/a>\n/2' | grep href | sort
You should see:
<a href="link1"></a>
<a href="link2"></a>
<a href="link3"></a>
..etc
easiest-way-to-extract-the-urls-from-an-html-page-using-sed-or-awk-only
vimdiff /path/to/file scp://user@remotehostip//path/to/file
root.cz - pouziti-vimu-a-jeho-pluginu-pro-porovnavani-a-slucovani-souboru
diff -r dir1 dir2 | grep dir1 | awk '{print $4}' > difference1.txt
Explanation:
- diff -r dir1 dir2 shows which files are only in dir1 and those only in dir2 and also the changes of the files present in both directories if any.
- diff -r dir1 dir2 | grep dir1 shows which files are only in dir1
- awk to print only filename.
diff -qr dir1 dir2
Files dir1/file1 and dir2/file1 differ
Only in dir1: file2
Only in dir2: file3
difference-between-two-directories-in-linux
root.cz - nastroje-pro-porovnani-obsahu-dvou-textovych-souboru
touch -h -t 201301291810 myfile.txt
[[CC]YY]MMDDhhmm[.ss]
Mandatory arguments to long options are mandatory for short options too.
-a change only the access time
-c, --no-create do not create any files
-d, --date=STRING parse STRING and use it instead of current time
-f (ignored)
-h, --no-dereference affect each symbolic link instead of any referenced
file (useful only on systems that can change the
timestamps of a symlink)
-m change only the modification time
-r, --reference=FILE use this file's times instead of current time
-t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time
changing-the-timestamp-of-a-symlink
ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1
$ 192.168.XXX.XXX
displaying-ip-address-on-eth0-interface
awk '/32 host/ { print f } {f=$2}' <<< "$(</proc/net/fib_trie)"
how-to-get-the-ipv4-address-for-an-interface-from-proc
pam_tally2 -u your_user --reset
cant-unlock-linux-user-account
pam_tally2 --file /var/log/tallylog
Login Failures Latest failure From
root 3 0X/XX/XX XX:XX:XX pts/1
apache 1 0X/XX/XX XX:XX:XX pts/2
xargs -0 printf '%s\n' < /proc/14805/cmdline
-server
-Xms256m
-Xmx512m
-XX:MaxPermSize=512m
...
xargs --null --max-args=1 echo < /proc/<PID>/environ
echo 'url=' | sed "s#url=#http://localhost:80#g"
url=http://localhost:80
how-to-use-sed-to-find-and-replace-url-strings-with-the-character-in-the-tar
grep -iR --color '<pattern>' --exclude=\*.{log*,out*} .
will exclude files with *.log, *.out filetypes
date -s "$(date +'%Y12%d %H:%M')"
Mon Dec 22 10:55:03 GMT 2014
changes the month to the 12th month - December. Time si preserved.
linux-set-date-through-command-line
sudo ss -plnt | awk '{ print $4 }' | cut -d ']' -f 2 | cut -d ':' -f 2 | sort -n | uniq
TODO:
- Describe ss command
- Describe http://stackoverflow.com/questions/11897662/identify-other-end-of-a-unix-domain-socket-connection TODO: Describe this commands
- yum whatprovides */libcrypto.so.10
- repoquery --requires --recursive --resolve postgis
- how-do-i-tell-a-script-to-wait-for-a-process-to-start-accepting-requests-on-a-po