Basic Linux Commands Flashcards
Linux commands
• The command line - Terminal, XTerm, or similar
• Commands are similar in both Linux and Mac OS
• Mac OS derived from
BSD (Berkeley Software Distribution) Unix
• This section is specific to Linux
- Download a Live CD or install a virtual machine
- Many pre-made Linux distributions are available
- I’m using Ubuntu in a virtual machine
- Use the man command for help
- An online manual
- > man grep
ls
- List directory contents
- Similar to the dir command in Windows
• Lists files, directories
• May support color coding;
• Blue is a directory,
red is an archive file, etc.
- For long output, pipe through more:
- > ls -l | more
- (use q or Ctrl-c to exit)
grep
- Find text in a file
- Search through many files at a time
- grep PATTERN [FILE]
- > grep failed auth.log
cd
- Change current directory
- Nearly identical to Windows command line
- Forward slashes instead of backward
- cd
- > cd /var/log
shutdown
- Shut the system down
- Safely turn off the computer in software
- Similar to the Windows shutdown command
•sudo shutdown 2
• Shuts down and turns off the computer
in two minutes
- sudo shutdown -r 2
- Shuts down and reboots in two minutes
- Important when you’re not on site
•Ctrl-C to cancel
pwd
- Print Working Directory
- Displays the current working directory path
- Useful when changing directories ofte
passwd
- Change a user account password
- Yours or another
- passwd [username]
mv
- Move a file
- Rename a file
- mv SOURCE DEST
- > mv first.txt second.txt
cp
- Copy a file
- Duplicate files or directories
- cp SOURCE DEST
- > cp first.txt second.txt
rm
- Remove files or directories
- Deletes the files
• Does not remove directories by default
• Directories must be empty to be removed or
must be removed with -r
mkdir
- Make a directory
- Create a folder for file storage
- mkdir DIRECTORY
- > mkdir notes
chmod
• Change mode of a file system object • r=read, w=write, x=execute • Can also use octal notation • Set for the file owner (u), the group(g), others(o), or all(a)
- chmod mode FILE
- > chmod 744 script.sh
- chmod 744 first.txt
- User; read, write execute
- Group; read only
- Other; read only
- chmod a-w first.txt
- All users, no writing to first.txt
- chmod u+x script.sh
- The owner of script.sh can execute the file
chown
- Change file owner and group
- Modify file settings
- sudo chown [OWNER:GROUP] file
- > sudo chown professor script.sh
•iwconfig
- View or change wireless network configuration
- essid, frequency/channel, mode, rate, etc.
- Requires some knowledge of the wireless network
- iwconfig eth0 essid studio-wireless
•ifconfig
• View or configure a network interface and
IP configuration
•ifconfig eth0
ps
- View the current processes
- And the process ID (PID)
- Similar to the Windows Task Manager
- View user processes
- ps
- View all processes
- ps -e | more
su / sudo
- Some command require elevated rights
* There are some things normal users can’t do
•su
- Become super user
- Or change to a different user
- You continue to be that user until you exit
•sudo
- Execute a command as the super user
- Or as a different user ID
- Only that command executes as the super user
apt-get
- Advanced Packaging Tool
- Handles the management of application packages
- Applications and utilities
- Install, update, remove
- > sudo apt-get install wireshark
vi
- Visual mode editor
- Full screen editing with copy, paste, and more
- vi FILE
- > vi script.sh
• Insert tex
- i
- Exit insert mode with Esc
- Save (write) the file and quit vi
- :wq
dd
- Convert and copy a file
- Backup and restore an entire partition
- > dd if= of=
[Options] • Creating a disk image •> dd if=/dev/sda of=/tmp/sda-image.img • Restoring from an image •> dd if=/tmp/sda-image.img of=/dev/sda
Closing programs
• Use terminal - sudo for proper permissions
- killall
- sudo killall firefox
- xkill
- Graphical kill
•kill
A user calls the helpdesk wanting a simple method he can use for backing up multiple large directories on a Linux system. What command allows users to back up and compress large directories?
tar