Linux Linux help

Linux Commands

1. How do I type in commands rather than use the desktop?

Linux comes with a command prompt. You can access it via Terminal on the menu. This will start the bash (bourne again shell) shell. This will bring up a window, similar to below:

Terminal

The username, hostname and current directory is displayed followed by a flashing block cursor. To exit this window, type exit or click on the X on top right of the window.

2. What commands are available to use with Linux?

Commands can be run from the current directory or those listed in the command path. The command path can be viewed by typing echo $PATH and can updated via the .bashrc login script. Most commands are available in the /bin, /sbin, /usr/bin or /usr/sbin folders. To view the parameters of the command you can type either man <command> or <command> --help (or -h). Commands can be combined using the pipe (|) character e.g. cat file | more.

File System Commands Purpose
bash Start a new bash session.
cd <directory> Change directory. Root directory is '\'.
cp <source> <dest> Copy one or more files (the ? and * wildcards can be used to select files)
rm <files> Remove one or more files
mkdir <directory> Make or create a directory
rmdir <directory> Remove or delete a directory
mv<orig> <new> Rename or move file(s)
cat <file> Display contents of a text file
more <file> Display contents of a file a screen at a time
vi <file> Change contents of a file using vim editor
nano <file> User friendly text editor
sed <expr> <file> Edit file using regular expressions on command line
grep "string" <file(s)> Search for string in a file
diff <file1> <file2> Compare two files and show differences
which <file> Locate file in command path
ls List files and folders
chmod Change file permissions
date Display date and time
df Display disk filesystems
du Disk usage display
touch <file> Change file's timestamp
gzip Compress file(s) into a gzip file
gunzip Uncompress files from gzip file
tar Compress file(s) into a tape archive (tar) file
chown Change owner of file.
pwd Print working directory to screen
unzip Unzip files from zip file
Disk Commands  
blkid View block device identity and attributes.
defrag Defragment a filesystem
fdisk Disk partitioning tool
fsck File system check
lsblk List block devices
lsusb List usb drives
mkfs[.filesys] Make a filesystem
mount, umount Mount or unmount a filesystem e.g. removable disks
parted Disk and partition editor
su Super user mode (Unix systems)
sudo Super user do command
cryptsetup Use LUKS to encrypt volumes
Users and Groups  
adduser, addgroup Add local users and groups
deluser, delgroup Delete a local user or group
passwd Change user password
groups List groups
usermod Modify a user, and add user to groups
Networking Commands  
ftp File Transfer protocol
hostname Display PC's hostname
ifconfig Display network interface config e.g. eth0
nslookup Name server lookup
ping <address> Ping a machine's IP address or hostname
ssh <hostname> Secure shell connection to host
scp Secure copy protocol
Other Commands Purpose
echo "text" Display text
crontab Set up scheduled tasks
arp Settings for Address Resolution protocol
which "file" Display location of a file
ps List running processes
perl <file> Run a Perl script
ln -a <src> <dest> Create a link to a file
ldconfig Libary cache management
history Command history utility
lspci Display installed PCI drivers
dmesg Display boot log messages
shutdown Shutdown or restart computer
apt-get Get and install packages from a distribution point
rpm Redhat package manager
yum Redhat package manager
dpkg Debian package manager
exit Close shell session
kill Kill a process or task
echo $PATH Display command path
man <command> Display manual for command (help)
lsmod List modules and device
rmmod Remove modules and devices
insmod Add modules and devices
service List, start, stop and show status of upstart services
systemctl List, start, stop, enable and show status of systemd services
sysctl System control settings for hardware. See /proc/sys

3. How do I change the colours for the command prompt?

Open a command window, select the Edit menu and then Profile Preferences. Select Colours tab and untick 'Use colours from system theme' and then you can change text and background colours. You can modify the .bashrc file in your home folder, and uncomment the line force_color_prompt=yes which will modify the PS1 environment variable to colorise the command prompt.

4. How do I change the command prompt text?

By default, the command prompt is the user, profile and current path followed by an $ e.g. user$host ~ $ which is set by the command $PS1 = "string". For example, current user is /u, current host is /h, current path is /w, current shell name is/s. For a complete list see Bash Prompt strings.

5. Where do I change bash start script settings?

In bash each user can have a .bashrc file in their home folder which contains startup scripts to configure their personal bash shell such as the prompt string, command aliases, set environment variables (.bash_profile) and so on. Type ls -la in your home directory to view these files.

6. How do I view the history of commands?

The history command will display a list of commands you have last used in the current and previous sessions. They are also stored in the .bash_history file in your profile.Use the up and down arrow keys to recall the last or next command used in your history. Use the tab key for auto-completion of filenames to save typing.

7. Some commands use regular expressions. What are they?

Normally you can use the standard wildcard characters such as * (match any character) and ? (a single character). But you might want more finer or advanced control on strings, so you must learn regular expressions e.g. ^*\.txt$ . See tutorial on learning regular expressions.

New Features