- Create short cut to a command using alias
Now, instead of typing cd /home/username/Desktop, you can simply move to the Desktop by typing 'Desktop' in the command prompt
Code: Select all
alias Desktop='cd /home/username/Desktop'
This creates an alias called list, which will use the ls command to print a long-style listing of all files in the current directory (the -l gives a long-style list, and the -a shows all files - including hidden files)Code: Select all
alias list='ls -la'
- Use apt-get (APT:Advanced Package Tool) for Debian and Ubuntu Linux to install packages over internet using ftp or http/https protocols, for upgrading all system packages in a single operation, for removing packages as well and other usage
Install package:Install several packages with a single operationsCode: Select all
apt-get install {package-name}
Upgrade all packages at onceCode: Select all
apt-get install {package-name} {package-name} {package-name} ...
Upgrade a single packageCode: Select all
apt-get upgrade
TryCode: Select all
apt-get upgrade {package-name}
Remove package but keep the configuration filesCode: Select all
apt-get upgrade {package-name} -u
Remove package and all the configuration filesCode: Select all
apt-get remove {package-name}
Search for a package name if you don't remember/know it but you are aware of some keywordsCode: Select all
apt-get --purge remove {package-name}
Code: Select all
apt-cache search "Text-to-search"
Display package dependencies (a list of other packages on which a package depends on)Code: Select all
apt-cache search "web server" | grep https
NB: Check "aptitude" - a text-based interface to the Debian GNU/Linux package system and Synaptic Package Manager (GUI fron end for APT).Code: Select all
apt-cache depends {package-name}
- Spell checking a file interactively with Aspell
Code: Select all
aspell check filename
- Compress and decompress files using bzip2 command at a high rate
Compress a single file and remove the original fileCompress multiple files at once, remove originalsCode: Select all
bzip2 filename
Create a compressed copy of a file and keep the originalCode: Select all
bzip2 file1 file2 file3
See more, bzip2Code: Select all
bzip2 -c file > file.bz
- Read, modify, concatenate text files or display the contents of a file using Unix/Linux Cat command (cat comes from the word conCATenate or glue together two or more files)
Display the contents of the motd (messages of the day) file to your screenCat's output to a device, e.g., a printer or modemCode: Select all
cat /etc/motd
Concatenate files into one big fileCode: Select all
cat /etc/motd > /dev/modem
Code: Select all
cat file1 file2 file3 output bigfile
- Most popular commands for files, directory and jobs
Delete empty directory:Remove/delete directory and its contents repeatedly:Code: Select all
rmdir dir
This would present a prompt for approval to delete each of the files. If you don't want to receive a prompt for each file, use the following command instead:Code: Select all
rm -r directory
Remove a number of files that start with "file.234."Code: Select all
rm -rf dir
Rename directory:Code: Select all
rm file.234*
Check human readable size of each file/directory in a directory including the container directory itself:Code: Select all
mv old_name new_name
Move to home directoryCode: Select all
du -h directory_name
Print the current working directory:Code: Select all
cd ~
Submit job by using bash script(bas-script is the name of the script)Code: Select all
pwd
Create a link (-s means soft link):Code: Select all
sbatch bash-script
Code: Select all
ln -s target_dir linkname
For example:Remove link:Code: Select all
ln -s target_directory_name pipeline
List everything including those in directories:Code: Select all
rm pipeline
Open the bash profile/bashrc to set PATH/environment variable (e.g., PYTHON variable):Code: Select all
ls -l
orCode: Select all
vim ~/.bash_profile
Rename in a path:Code: Select all
vim ~/.bashrc
Search for text and replace:Code: Select all
mv ../old_directory/new_directory/* ./
Code: Select all
sed -i 's/original/new/g' fname.txt
- sed = Stream EDitor
- -i = in-place (i.e. save back to the original file)
- s = the substitute command
- original = a regular expression describing the word to replace (or just the word itself)
- new = the text to replace it with
- g = global (that's, replace all and not just the first occurrence)
- fname.txt = the file name
where JOBID is the job IDCode: Select all
scancel JOBID
- Open/Create
Open a directory:Open website by using a default browser:Code: Select all
nautilus directory_name
For example:Code: Select all
xdg-open url
Use specific browser e.g., firefox to open web:Code: Select all
xdg-open https://forums.tssfl.com
Use any editor, e.g., gedit to create a file and write contents in it (start with the name of editor, followed by filename):Code: Select all
firefox url
Code: Select all
gedit filename
-
- Active Topics
-
-
- by Eli 7 hours ago Re: What is in Your Mind? View the latest post Replies 687 Views 274117
- by Eli 1 day ago Iran Launches Retaliatory Attack Against Israel, and Israel Retaliates by Attacking Iranian Isfahan Millitary Base View the latest post Replies 28 Views 886
- by Eli 3 days ago All in One: YouTube, TED, X, Facebook and Instagram Reels, Videos, Images and Text Posts View the latest post Replies 319 Views 8982
- by Eli 5 days ago Python Packages for Scientific Computing View the latest post Replies 8 Views 3004
- by Eli 5 days ago Dunia Yetu: Building Tanzania's Digital Future Together View the latest post Replies 5 Views 1842
- by Eli 1 week ago Russia Invades Ukraine View the latest post Replies 646 Views 210467
- by Eli 1 week ago Programmatically Move Files from One Folder to Another View the latest post Replies 6 Views 1430
- by Eli 2 weeks ago Collection of Greatest Christian Hymns of all Times View the latest post Replies 33 Views 43746
- by Eli 2 weeks ago What is Retrieval-Augmented Generation (RAG)? View the latest post Replies 2 Views 360
- by Eli 2 weeks ago Chat With ChatGPT - An Interactive Conversational AI View the latest post Replies 22 Views 24362
-
Linux shell/bash commands
- Eli
- Senior Expert Member
- Reactions: 183
- Posts: 5332
- Joined: 9 years ago
- Location: Tanzania
- Has thanked: 75 times
- Been thanked: 88 times
- Contact:
Here is a list of some common Linux shell/bash commands , for most of the Linux distributions that you will actually need to use for work.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
-
- Similar Topics
- Replies
- Views
- Last post
-
- Information
-
Who is online
Users browsing this forum: No registered users and 0 guests