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 Path and can be edited via the System Control Panel, Advanced, Environmental Variables. Most commands are available in the C:\Windows\System32 folder. To view the parameters of the command you can type either Help <command> or <command> /? (slash, question mark). Commands can be combined using the pipe (|) character e.g. Type 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
grep "string" <file(s)> Search for string in a file
diff <file1> <file2> Compare two files and show differences
ls List files and folders
chmod Change file permissions
date Display date and time
touch <file> Change file's timestamp
gzip Compress file(s) into a gzip file
tar Compress file(s) into a tape archive (tar) file
chown Change owner of file.
pwd Print working directory to screen
Disk Commands  
defrag Defragment a filesystem
fdisk Disk partitioning tool
fsck File system check
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
Users and Groups  
adduser, addgroup Add local users and groups
deluser, delgroup Delete a local user or group
passwd Change user password
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
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 Create a link to a file
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
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)

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.

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.