Basic Commands - Linux


Identifying the IP address
[pre class="brush:bash"]
ip addr show
[/pre]
Changing the default password
[pre class="brush:bash"]
passwd
[/pre]
Display the amount of disk space available
[pre class="brush:bash"]
df -h # -h: human readable output format
[/pre]
scp copy
[pre class="brush:bash"]
scp /path/to/file username@a:/path/to/destination
scp username@b:/path/to/file /path/to/destination
[/pre]
Executing a command at a fixed interval using watch command
[pre class="brush:bash"]
watch -n x command
# "x" is the repeat time in seconds;"command" is the command that you want to execute
[/pre]
Running a command at a fixed interval
[pre class="brush:bash"]
while true; do
cmd >> output.txt
sleep 2
done

while true; do sleep 2; cmd >>output.txt; done &

[/pre]
Running a command in background
[pre class="brush:bash"]
nohup command &
[/pre]
Show the list of installed packages in Ubuntu or Debian
[pre class="brush:bash"]
dpkg --get-selections
[/pre]
Check the capacity of a directory
[pre class="brush:bash"]
du -sh /path/directory
# h: human readable output; s: total disk space used by the directory
[/pre]
Installing ffmpeg from ppa depository (add ppa to apt apt-get and install)
[pre class="brush:bash"]
# http://askubuntu.com/questions/645462/avconv-version-and-youtube-dl
sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install ffmpeg
[/pre]
Get the version of the libav-tools
[pre class="brush:bash"]
# http://askubuntu.com/questions/645462/avconv-version-and-youtube-dl
apt-cache search libav | grep libav
[/pre]
Execute modified command when called by adding alias to the bashrc file (source)
[pre class="brush:bash"]
# http://askubuntu.com/questions/645462/avconv-version-and-youtube-dl
echo "alias youtube-dl='youtube-dl --prefer-ffmpeg'" | tee -a ~/.bashrc; . ~/.bashrc
# alternatively, you can edit this file by opening this file from your home directory
vim .bashrc
[/pre]
Installing OpenVPN client and import *.ovpn (Windows) file to configure
[pre class="brush:bash"]
sudo apt-get install openvpn
sudo apt-get install network-manager-openvpn-gnome
# Now goto the network settings on the system tray -> “vpn connections” -> “configure vpn” ->
# “Add” -> select “Import saved VPN configuration” from the drop down list - > “create” ->
# select the *.ovpn file -> finally, type the username and password and click “ok”.
# Now go to the network settings and connect to the configured VPN server.
[/pre]
Counting the number of files in a directory and sub-directories (source)
[pre class="brush:bash"]
find . -type f | wc -l
# . - this directory and all subdirectories
# -type f - find all files
# | - piped into wc - word count and the -l - tells to count the lines from wc

# or

find . | wc -l
# this counts the files and directories within the current directory.
[/pre]
Extract a process detail from top command based on process name
[pre class="brush:bash"]
top -c -p $(pgrep -d',' -f youtube-dl)
# joining MP3 files to a single track
cat *.mp3 > out.mp3
[/pre]
Spitting a MP3 files into multiple files (source)
[pre class="brush:bash"]
ffmpeg -i 01.mp3 -f segment -segment_time 100 -c copy 01_%03d.mp3
[/pre]
Joining MP3 files to a single track:[pre class="brush:bash"]
cat *.mp3 > out.mp3
[/pre]
Copy/Sync a Directory on Local Computer
[pre class="brush:bash"]
rsync -avzh /root/rpmpkgs /tmp/backups/[/pre]
chmod
[pre class="brush:bash"]
chmod 700 myDir #7-user; 0:Group; 0: Others - read(4), write(2), execute(1)
[/pre]
List all the directories with sizes
[pre class="brush:bash"]
du -sh *
du: disk usage
# -s: Display an entry for each specified file
# -h: human readable format
du -sh * | sort -n # sort folders by size
du -sh * | tail -r # sort by largest first
[/pre]
List all the processes associated with a process-name
[pre class="brush:bash"]
ps -fC process-name
[/pre]
Deleting an entry from history 
[pre class="brush:bash"]
history -d line_number
[/pre]
List all the installed packages
[pre class="brush:bash"]
apt list --installed
[/pre]
Changing password of another user
[pre class="brush:bash"]
sudo passwd user_name
[/pre]
Terminal execute commands as another user
[pre class="brush:bash"]
sudo su user_name
[/pre]
Find UID of a user
[pre class="brush:bash"]
id -u user_name
[/pre]
Find GID of a user
[pre class="brush:bash"]
id -g user_name
[/pre]
Find all the groups a user belongs to
[pre class="brush:bash"]
id -G user_name
[/pre]
Find all the groups associated with UID
[pre class="brush:bash"]
id user_name
[/pre]
Disable sudo password for a particular user
[pre class="brush:bash"]
sudo vim /etc/sudoers
#add the following to the above file
user_name ALL=(ALL) NOPASSWD:ALL
[/pre]
Renaming all files in a folder (Amend for eg: unix_)
[pre class="brush:bash"]
rename 's/^/Unix_/' *
[/pre]




You may also interested in reading:

No comments:

Post a Comment