Basic Linux Commands
Concepts Files & directories
- Everything is a file
- 256 characters maximum
- Case sensitive
- Special characters
- Begin with . (period)
- Don’t use /, ?, *, –
- Avoid spaces; use underscores instead
- Extension not necessary
File system
- Hierarchical tree
- No drive letters
- Starts at root with /
Getting Information
man
man [command]
Within man:
- spacebar/f = forward
- b = back
- q = quit
- / = search forward
- ? = search backward
- n = repeat search
info
info [command]
info info
Enter ‘m’ & enter program name
Viewing Files
cat
Display file to STDOUT
cat [file]
more or less
Display STDOUT screen by screen
more [file]
less [file]
Within more:
- spacebar/f = forward
- b = back
- q = quit
ls | less
head
View the first lines of a text file
head file.txt = show first 10 lines of file
head -25 file.txt = show first 25 lines of file
tail
View the last lines of a text file
tail file.txt = show last 10 lines of file
tail -25 file.txt = show last 25 lines of file
Getting Around
cd
cd ~
cd .
cd ..
ls
ls -a
ls -l
lrwxrwxrwx # owner group size_in_bytes last_modified_date_&_time filename.txt ^\_/\_/\_/ | v v v | | | | | | | World permissions | | | | | Group permissions | | | Owner permissions | Type of file: - = file l = link d = directory b = block device (disk drive) c = character device (serial port or terminal)
ls -la
ll
ls -F
Classify special files with a character after the file name
- * = executable
- / = directory
- = = socket
- @ = alias
- | = FIFO
- No character = normal file
ls [directory name]
pwd
Display absolute path
pwd
Changing Permissions & Ownership
chmod
r = read = 4
- If file: view contents
- If directory: list contents
w = write = 2
- If file: modify
- If directory: add or remove files
x = execute = 1
- If file: run file as command
- If directory: access files contained inside
u = user
g = group
o = others
a = all
chmod 744 file
chmod -r 744 file
chmod a+x file
chmod a-x file
chmod a+rw-x file
chown
File Information
chown [username] file
chown [username].[groupname] file
file
file [filename]
od
Octal dump of files
Files & Directories
cp
cp /path/to/file /path/to/new/file
cp /path/to/file .
cp file directory/
cp -F
cp -r directory/ directory/
cp -i file file
mv
mv file newfile
mv file directory/
mv directory/ directory/
mv -i file file
mkdir
mkdir [directoryname]
rm
rm file
rm *
rm -i filename
rm -r directory
rm -f file
rm -rf directory
rm -rf /*
Do NOT do this!
rmdir
rmdir
Note: directory must be empty; since that’s often a pain, you can use “rm -rf directory-name” instead, but be careful!
ln
ln [original_file_name] [new_file_name]
Creates a hard link
ln -s [new_file_name] [original_file_name]
Creates a soft link
Finding
find
find / -name *gnome* -print
find / -type d -maxdepth 1
find -name [name] -group [group] -size [size] -mtime [number of days ago] – type [b|c|d|f|l]
locate
locate file-or-directory
updatedb
Update the database used by the “locate” command
whereis
whereis [command]
System Information
free
How much memory is used & unused
Note that you can use this to get even more info: cat /proc/meminfo
df
Disk usage for all mounted drives
du
Disk usage for the current directory and all subdirectories
du -h
Show results in human-readable form (kb & MB)
These details were copied from:
http://www.granneman.com/techinfo/linux/commandline/basiccommands/