Commands
---------
Create a new folder named test33 and jump into it
[root@nglinux]#mkdir test33; cd $_ [root@nglinux test33]#
resolve mlocate command not working issue on CentOS 7 or RHEL 7
1. Remove old mlocate Database.
# rm /var/lib/mlocate/mlocate.db
2. Update the Database now.
# updatedb
After this, the issue with mlocate should be resolved
______________________ XXXXXXXX------------------------
log file under /var/log, you want to delete old logs
### Now lets say i have to delete all logs older than 2 days i.e. 12th Jan.### Run below command to edit the message file at the exiting location and to delete logs older than 12th Jan.[root@nglinux ~]# a=`grep -in "Jan 12" messages | head -1 | cut -d ":" -f1`; sed -i "1,$a d" messages
Check for which log file under /var/log, you want to delete old logs.
### For example:- my messages file has logs from 7th January to 14th January.[root@nglinux log]# more messages Jan 7 03:13:07 localhost rsyslogd: [origin software="rsyslogd" swVersion="5.8.10" x-pid="1767" x-info="http://www.rsyslog.com"] rsyslogd was HUPedJan 7 03:13:21 localhost kernel: dd invoked oom-killer: gfp_mask=0xd0, order=0, oom_adj=0, oom_score_adj=0Jan 7 03:13:21 localhost kernel: dd cpuset=/ mems_allowed=0Jan 7 03:13:21 localhost kernel: Pid: 5890, comm: dd Not tainted 2.6.32-696.el6.i686 #1Jan 7 03:13:21 localhost kernel: Call Trace:Jan 7 03:13:21 localhost kernel: [] ? dump_header+0x84/0x190..........Jan 14 02:56:11 localhost rtkit-daemon[2816]: Successfully demoted thread 7841 of process 7822 (/usr/bin/pulseaudio).Jan 14 02:56:11 localhost rtkit-daemon[2816]: Successfully demoted thread 7822 of process 7822 (/usr/bin/pulseaudio).Jan 14 02:56:11 localhost rtkit-daemon[2816]: Demoted 3 threads.Jan 14 03:33:28 localhost rsyslogd: [origin software="rsyslogd" swVersion="5.8.10" x-pid="1767" x-info="http://www.rsyslog.com"] rsyslogd was HUPed
2. Delete logs older than a specified date.
### Now lets say i have to delete all logs older than 2 days i.e. 12th Jan.### Run below command to edit the message file at the exiting location and to delete logs older than 12th Jan.[root@nglinux ~]# a=`grep -in "Jan 12" messages | head -1 | cut -d ":" -f1`; sed -i "1,$a d" messages
3. View the file now.
The old logs are now erased, and now we have only logs starting from 12th Jan to 14th Jan.
[root@nglinux ~]# more messages Jan 12 08:02:39 localhost rtkit-daemon[2816]: Demoting known real-time threads.Jan 12 08:02:39 localhost rtkit-daemon[2816]: Successfully demoted thread 7848 of process 7822 (/usr/bin/pul seaudio).Jan 12 08:02:39 localhost rtkit-daemon[2816]: Successfully demoted thread 7841 of process 7822 (/usr/bin/pul seaudio).Jan 12 08:02:39 localhost rtkit-daemon[2816]: Successfully demoted thread 7822 of process 7822 (/usr/bin/pul seaudio).Jan 12 08:02:39 localhost rtkit-daemon[2816]: Demoted 3 threads.Jan 14 02:32:46 localhost rtkit-daemon[2816]: Demoted 3 threads.Jan 14 02:46:53 localhost rtkit-daemon[2816]: The canary thread is apparently starving. Taking action.Jan 14 02:46:53 localhost rtkit-daemon[2816]: Demoting known real-time threads.Jan 14 02:46:53 localhost rtkit-daemon[2816]: Successfully demoted thread 7848 of process 7822 (/usr/bin/pul seaudio).Jan 14 02:46:53 localhost rtkit-daemon[2816]: Successfully demoted thread 7841 of process 7822 (/usr/bin/pul seaudio).Jan 14 02:46:53 localhost rtkit-daemon[2816]: Successfully demoted thread 7822 of process 7822 (/usr/bin/pul seaudio).Jan 14 02:51:32 localhost rtkit-daemon[2816]: Demoted 3 threads.Jan 14 02:56:11 localhost rtkit-daemon[2816]: The canary thread is apparently starving. Taking action.Jan 14 02:56:11 localhost rtkit-daemon[2816]: Demoting known real-time threads.Jan 14 02:56:11 localhost rtkit-daemon[2816]: Successfully demoted thread 7848 of process 7822 (/usr/bin/pul seaudio).Jan 14 02:56:11 localhost rtkit-daemon[2816]: Successfully demoted thread 7841 of process 7822 (/usr/bin/pul seaudio).Jan 14 02:56:11 localhost rtkit-daemon[2816]: Successfully demoted thread 7822 of process 7822 (/usr/bin/pul seaudio).Jan 14 02:56:11 localhost rtkit-daemon[2816]: Demoted 3 threads.Jan 14 03:33:28 localhost rsyslogd: [origin software="rsyslogd" swVersion="5.8.10" x-pid="1767" x-info="http ://www.rsyslog.com"] rsyslogd was HUPed[root@nglinux ~]#
4. Verify reduced log file size.
### Old log size.[root@nglinux ~]# du -sh messages 320K messages ### New reduced log size.[root@nglinux ~]# du -sh messages 8.0K messages [root@nglinux ~]#
You can save this command and can use it to have specific logs of particular time to analyze instead of looking complete file.
---------------------------------
update RHEL, or centos major release version
RHEL 6 to RHEL 7
Redhat do not recommend and support such upgrade, however in rare scenario we can perform this migration using below steps.
1. Install required tools
# yum install redhat-upgrade-tool# yum install yum-utils
2. Disable all repos
# yum-config-manager --disable \*
3. Download latest RHEL 7 ISO from https://access.redhat.com/downloads.
And then upgrade to RHEL7 using ISO image downloaded.
# redhat-upgrade-tool --iso RHEL7_ISO_filepath --cleanup-post# reboot
-----XXX-------------------------
download youtube Videos & mp3 in Linux
1. Download & Install YouTube-DL Plugin
[root@ngelinux ~]# wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl --no-check-certificate--2018-02-20 03:29:50-- https://yt-dl.org/downloads/latest/youtube-dlResolving yt-dl.org... 95.143.172.170, 2001:1a50:11:0:5f:8f:acaa:177Connecting to yt-dl.org|95.143.172.170|:443... connected. WARNING: cannot verify yt-dl.org’s certificate, issued by “/C=EN/CN=Sample CA 2”: Unable to locally verify the issuer’s authority. HTTP request sent, awaiting response... 302 FoundLocation: https://yt-dl.org/downloads/2018.02.11/youtube-dl [following]--2018-02-20 03:29:52-- https://yt-dl.org/downloads/2018.02.11/youtube-dlConnecting to yt-dl.org|95.143.172.170|:443... connected. WARNING: cannot verify yt-dl.org’s certificate, issued by “/C=EN/CN=Sample CA 2”: Unable to locally verify the issuer’s authority. HTTP request sent, awaiting response... 302 FoundLocation: https://github.com/rg3/youtube-dl/releases/download/2018.02.11/youtube-dl [following]--2018-02-20 03:29:53-- https://github.com/rg3/youtube-dl/releases/download/2018.02.11/youtube-dlResolving github.com... 192.30.253.112, 192.30.253.113Connecting to github.com|192.30.253.112|:443... connected. WARNING: cannot verify github.com’s certificate, issued by “/C=EN/CN=Sample CA 2”: Unable to locally verify the issuer’s authority. HTTP request sent, awaiting response... 302 FoundLocation: https://github-production-release-asset-2e65be.s3.amazonaws.com/1039520/88b1e0de-0f7b-11e8-8d08-31123707063f?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20180220%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180220T112953Z&X-Amz-Expires=300&X-Amz-Signature=a0fb28151f13a157e3fb99147fcb10d33663b2523f89342b451193fd11f676ed&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dyoutube-dl&response-content-type=application%2Foctet-stream [following]--2018-02-20 03:29:55-- https://github-production-release-asset-2e65be.s3.amazonaws.com/1039520/88b1e0de-0f7b-11e8-8d08-31123707063f?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20180220%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180220T112953Z&X-Amz-Expires=300&X-Amz-Signature=a0fb28151f13a157e3fb99147fcb10d33663b2523f89342b451193fd11f676ed&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dyoutube-dl&response-content-type=application%2Foctet-streamResolving github-production-release-asset-2e65be.s3.amazonaws.com... 52.216.82.216Connecting to github-production-release-asset-2e65be.s3.amazonaws.com|52.216.82.216|:443... connected. WARNING: cannot verify github-production-release-asset-2e65be.s3.amazonaws.com’s certificate, issued by “/C=EN/CN=Sample CA 2”: Unable to locally verify the issuer’s authority. HTTP request sent, awaiting response... 200 OK Length: 1625851 (1.5M) [application/octet-stream]Saving to: “/usr/local/bin/youtube-dl”100%[==========================================================>] 1,625,851 163K/s in 10s 2018-02-20 03:30:07 (152 KB/s) - “/usr/local/bin/youtube-dl” saved [1625851/1625851][root@ngelinux ~]#
2. Set permissions of read & execute on youtube-dl application.
[root@ngelinux ~]# chmod a+rx /usr/local/bin/youtube-dl[root@ngelinux ~]#
3. List various screen resolution of youtube video available.
Below command lists various screen resolution like 360p,720p,1080p, etc.
[root@ngelinux ~]# youtube-dl -F https://www.youtube.com/watch?v=NFsEqOBG51M NFsEqOBG51M: Downloading webpage NFsEqOBG51M: Downloading video info webpage NFsEqOBG51M: Extracting video information NFsEqOBG51M: Downloading js player vfl8swg2e [info] Available formats for NFsEqOBG51M: format code extension resolution note 249 webm audio only DASH audio 69k , opus @ 50k, 2.27MiB250 webm audio only DASH audio 89k , opus @ 70k, 2.98MiB140 m4a audio only DASH audio 128k , m4a_dash container, mp4a.40.2@128k, 4.85MiB171 webm audio only DASH audio 156k , vorbis@128k, 5.30MiB251 webm audio only DASH audio 166k , opus @160k, 5.78MiB278 webm 256x144 144p 96k , webm container, vp9, 25fps, video only, 3.26MiB160 mp4 256x144 144p 113k , avc1.4d400c, 25fps, video only, 2.11MiB242 webm 426x240 240p 216k , vp9, 25fps, video only, 4.64MiB133 mp4 426x240 240p 249k , avc1.4d4015, 25fps, video only, 4.03MiB243 webm 640x360 360p 414k , vp9, 25fps, video only, 9.28MiB134 mp4 640x360 360p 570k , avc1.4d401e, 25fps, video only, 8.27MiB244 webm 854x480 480p 772k , vp9, 25fps, video only, 15.94MiB135 mp4 854x480 480p 1124k , avc1.4d401e, 25fps, video only, 16.98MiB247 webm 1280x720 720p 1449k , vp9, 25fps, video only, 25.11MiB136 mp4 1280x720 720p 1878k , avc1.4d401f, 25fps, video only, 27.81MiB248 webm 1920x1080 1080p 2538k , vp9, 25fps, video only, 45.04MiB137 mp4 1920x1080 1080p 2901k , avc1.640028, 25fps, video only, 45.04MiB17 3gp 176x144 small , mp4v.20.3, mp4a.40.2@ 24k36 3gp 320x180 small , mp4v.20.3, mp4a.40.243 webm 640x360 medium , vp8.0, vorbis@128k 18 mp4 640x360 medium , avc1.42001E, mp4a.40.2@ 96k22 mp4 1280x720 hd720 , avc1.64001F, mp4a.40.2@192k (best)[root@ngelinux ~]#
4. Download youtube video.
18 corresponds to 360p screen resolution as per the above output.
### Downloads the video to present working directory[root@ngelinux ~]# youtube-dl -f 18 https://www.youtube.com/watch?v=NaX-oGJEZI8 NaX-oGJEZI8: Downloading webpage NaX-oGJEZI8: Downloading video info webpage NaX-oGJEZI8: Extracting video information [download] Destination: Aaj Se Teri _ Padman _ Akshay Kumar & Radhika Apte _ Arijit Singh _ Amit Trivedi-NaX-oGJEZI8.mp4 [download] 100% of 13.24MiB in 00:28[root@ngelinux ~]# ### Verify if the video is downloaded[root@ngelinux ~]# ls -ltr | grep -i aaj -rw-r--r--. 1 root root 13878032 Dec 22 14:31 Aaj Se Teri _ Padman _ Akshay Kumar & Radhika Apte _ Arijit Singh _ Amit Trivedi-NaX-oGJEZI8.mp4 [root@ngelinux ~]#
5. How to Download MP3 Track from Youtube Video in Linux?
[root@ngelinux ~]# youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=NaX-oGJEZI8 NaX-oGJEZI8: Downloading webpage NaX-oGJEZI8: Downloading video info webpage WARNING: unable to download video info webpage: The read operation timed out NaX-oGJEZI8: Extracting video information [download] Destination: Aaj Se Teri _ Padman _ Akshay Kumar & Radhika Apte _ Arijit Singh _ Amit Trivedi-NaX-oGJEZI8.webm [download] 7.0% of 3.48MiB at 19.66KiB/s ETA 02:48
–audio-format specifies the audio format in which the file will be downloaded to our system.
The supported audio formats include “best”, “aac”, “vorbis”, “mp3”, “m4a”, “opus”, or “wav”.
“best” audio format is set by default.
--------