print name of current directory: pwd


View catalog files list:
ls
ls -l one file in a line
ls -f indicators
ls -s with size
ls -a all with hidden files
ls -r all subdirectories
dir


Create empty file 01.c:
touch 01.c
Change file time creation to current time
touch filename
Make copy of file:
cp 01.c 02.c
Delete file (remove)
rm 02.c
Create new directory
mkdir
datadir
Delete empty directory
rmdir
datadir
Output text file to console STDOUT
cat 01.c
Print to STDOUT with file numbers
cat -n prog.c
Input text from STDIN to file abc.txt. Stop input and return to shell: press CTRL-D
cat > abc.txt
ctrl-z
Concatenate two files a.txt and b.txt and save result in c.txt
cat a.txt b.txt > c.txt
Output big text file to console by pages
cat bigfile | more
Hex dump of a file (32 bit words)
od -x file
Character dump of a file
od -c file
Long(32 bit words) unsigned decimal dump
od -D file
Disassemble obj or exe file:
objdump -D prog.o
objdump -D a.out
Search a string in all files of current directory
grep "mystr" *
Show line number in addition
grep - n 'mstr' *
Clear screen
clear
Print all strings (len >= 4, end symbol 0) in a file
strings filename
List of important subdirectories of root directory:
/ - root directory itself
/bin - Essential command binaries
/dev - Contains all files that represent peripheral devices
/etc - Machine–local system configuration files
/home - User home directories
/lib - Shared libraries
/proc - Kernel and process information virtual filesystem
/sbin - Essential system binaries
/sys - Device pseudofilesystem
/usr - Includes subdirectories that contain information used by the system
/var - Variable data
Set simple command prompt
PS1=">" or PS1="\w>"
Bash prompt special characters
\w the current working dir
\! The history number of this command
Different console prompts settings
PS1="\S-\V\$" default
PS1="[\h\W\!]\S"
Print name of user root directory
echo ~
echo $HOME
Print names and values of all environment variables in shell
printenv
Make link to files and directories in other directories
ln -s /usr/include includelink
ln -s /usr/include/stdio.h st.h
Active processes listing
ps
Print first lines of a file
head file
head -30 file
Print last lines of a file
tail file
Print counts of characters, words and lines for a file
wc textfile
Find a file within linux OS
locate -i *main*
Add string to PATH variable: example: Add working dir to path
PATH =$PATH:.
Get name of host computer
hostname
Using echo utility:
echo "HelloConsole" #output string
echo $PS1 #output environment variable
echo " I need in Linux" > myfile.txt
Superuser command:
sudo "console command"
Get Documentation (Space = go forward, q = quit)
man ls
man gcc
man gdb
man man
Using more utility for text page review
ls -l /usr/include | more
Analyse type of file: utility file
file testedfile
Files search in file system
whereis ls (or gcc or gdb)
whereis stdio.h
mlocate stdlib
Commands:
nl, nm, ftp, sn, sum, uptime, w, who, sc, bc
High precision calculator bc
bc 123+456*789
bc after that we are inside interpreter
Here we can declare variables
Var1 = 123
Var2 = 345
Var3 = var1*var2
Summarize free disk space
df -T gives device types too
Change password
passwd
Convert tabs to spaces
expand
Disk usage:
du
Split big file into smaller pieces
dsplit -size inputfile outputfiles
Information about free and used memory
free
Calender output:
cal
Rewrite text file, breaking long lines to smaller ones
fold -width textfile > resultfile
Text file output to console (space = continue, q = quit):
more textfile
less textfile
File compression
bzip2 myfile
result misfile.bz2
File decompression
bunzip2 myfile.bz2
Help for utility
info utilityname
example:
help hexdump
host information:
hostid
hostname
hex dump of non text files
hexdump a.out
or
hexdump -c a.out
Process termination
kill processID #get processID from ps
Spelling test
ispell ...
Add line numbers to text file
nl test.txt > testn.txt
or
nl
List strings in object files
nm file.o
nm a.out
Shell variables: echo these variables
$PS1
$SHELL
$PATH
$HOME
$OS
...
Reset the terminal
reset
Pipes organizing examples
cat file.txt|more
ls|more
Many commands in one line:
command1; command2; command3;
Parse command line:
getopt ...
MS -DOS commands library
med
mcopy
mdel
mdeltree
mdir
mformat
mlabel
mmd
mmount
mmove
mrd
mread
mren
mtype
mtools
join
...?
Factorizing of integer number:
Factor integerNumber