0% found this document useful (0 votes)
8 views

deleted-124743_linux-basic-commands

Java linux cheet sheet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

deleted-124743_linux-basic-commands

Java linux cheet sheet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Linux Basic Commands Cheat Sheet

by [deleted] via cheatography.com/124743/cs/23886/

Basic comands Shell Globbing (Wildc​ards)

cat file1 file2 ... Print the contents of file1, * A number of any characters
file2, ... ? A single character
ls List the contents of a directory. [] Specify a range. [ab] can become: a, b. [a-c] can
ls -l Use a long listing format become: a, b, c

ls -a Do not ignore entries starting with . [!a-c] Any single character except a, b, c

cp file1 file2 Copy file1 to file2 Globbing is the operation that expands a wildcard pattern into the list
cp file1 ... fileN dir Copy a number of files to a of pathnames
directory It is applied on each of the components of a pathname separa​tely. /
in a pathname cannot be matched.
mv file1 file2 Rename file1 to file2
If filename starts with ., . must be matched explic​itly.
mv file1 ... fileN dir Move a number of files to a
Wildcard patterns are not regular expres​sions, they match filenames,
directory
not text.
touch file Create a file. If the file already
exists, touch does not change it Search files
rm file Remove a file grep RegEx file Search for regular expression
rm -r dir Recurs​ively remove all files and pattern in file
subdir​ect​ories in dir grep -i Case-i​nse​nsitive search
echo Print echo's arguments to the grep -v Print all lines that don't match
standard output
find dir -name file -print Find file in dir and display
pwd Print working directory
the pathname of it
pwd -P Print true full path, not path of locate file Search an index that the
symbolic link system builds period​ically
sudo command Run command as root
Display a file
Navigating Direct​ories
less file Display the contents of file one screenful at a time
cd dir Change the shell's current working directory spacebar Go forward one screenful
mkdir dir Create a new directory b Skip back one screenful
rmdir dir Remove the directory dir if dir is empty /word Search forward for word
Linux has a directory hierarchy starts at / (root directory). ?word Search backward for word
Directory separator is the slash (/).
q Quit less
Two dots (..) refers to the parent of a directory.
head file Display the first 10 lines of file
One dot (.) refers to the current directory.
tail file Display the last 10 lines of file

By [deleted] Published 3rd August, 2020. Sponsored by Readable.com


cheatography.com/deleted- Last updated 3rd August, 2020. Measure your website readability!
124743/ Page 1 of 4. https://readable.com
Linux Basic Commands Cheat Sheet
by [deleted] via cheatography.com/124743/cs/23886/

Differ​ences between text files Comman​d-Line Editing

diff file1 file2 Print differ​ences between two text files CTRL-B Move the cursor left

diff --color Print differ​ences with color CTRL-F Move the cursor right

diff -y Print differ​ences side by side CTRL-A Move the cursor to the beginning of the line

diff -c View differ​ences in context mode CTRL-E Move the cursor to the end of the line

diff -i Ignore case differ​ences CTRL-W Erase the preceding word

diff -w Ignore all white space CTRL-U Erase from cursor to beginning of line
CTRL-K Erase from cursor to end of line
diff gives the instru​ctions on how to change the first file to make it
match the second file. CTRL-Y Paste erased text

< denotes lines in file1. > denotes lines in file2. CTRL-D Stop the current standard input entry from the terminal
Change command
LaR: Add the lines in range R of the second file after line L of the first Getting Online Help
file. man command Show manual page for command
FcT: Replace the lines in range F of the first file with lines in range T
man -k Search for a manual page by keyword
of the second file.
keyword
RdL: Delete the lines in range R from the first file so that both the
man n command Show manual page for command from section n
files sync up at line L.
Online Manual Sections
Enviro​nment and Shell Variables 1 User commands
stuff=blah Create a shell variab​le/​Assign a value to a 2 System calls
variable 3 Higher​-level Unix progra​mming library docume​‐
PATH=$PATH:dir Appends ":dir" to the end of PATH variable ntation
$STUFF Access a variable 4 Device interface and driver inform​ation

export STUFF Make $STUFF shell variable into an enviro​‐ 5 File descri​ptions (system config​uration files)
nment variable 6 Games
unset STUFF Delete variable STUFF 7 File formats, conven​tions, and encodings
env Prints enviro​nment variables (ASCII, suffixes, and so on)
8 System commands and servers
Shell variables are variables whose scope is in the current shell
session. Manual pages cover the essent​ials, but there are many more ways to
Enviro​nment variables are shell variables which has been exported. get online help. Try entering a command name followed by --help
Children processes get their own copy of the parent variables so they or -h to look for a certain option for a command
can never change the enviro​nment variables in their parent process.
Enviro​nment variables must be name=value pair.
Command path
PATH is enviro​nment variable that contains command path (list of
system direct​ories that the shell searches when trying to locate a
command).

By [deleted] Published 3rd August, 2020. Sponsored by Readable.com


cheatography.com/deleted- Last updated 3rd August, 2020. Measure your website readability!
124743/ Page 2 of 4. https://readable.com
Linux Basic Commands Cheat Sheet
by [deleted] via cheatography.com/124743/cs/23886/

Shell Input and Output Listing and Manipu​lating Processes (cont)

command > file Send the output of command to a file jobs -l List the active jobs with their status and pid (-l)

command >> file Append output to the file fg %n Move job that have job number n to the foreground

command < file Channel a file to a program's standard bg %n Move job that have job number n to the background
input command & Run command in background
command1 | command2 Send the standard output of command1
The ps command has many options. Options can be specified in
to the standard input of command2
three different styles​—Unix, BSD, and GNU. Above commands use
command 2> file Redirect the standard error (2 is BSD style.
standard error stream ID)
command &> file Redirect the all output to file File Modes and Permis​sions

command 2>&1 Send standard error to the same place File's mode represents the file's permission and some extra inform​‐
as standard output ation. There is 4 parts to the mode. First character is file type. The
rest contains the permis​sions, which break down into three sets:
Listing and Manipu​lating Processes user, group, other, in that order. Each set can contain four basic
repres​ent​ations:
ps List processes owned by root
r Means that the file is readable
ps x List all processes owned by you
w Means that the file is writable
ps ax List all processes on the system
x Means that the file is executable
ps u Include more detailed inform​ation
on processes - Means nothing

ps w Show full command names Modifying Permis​sions


chmod ugo+r file Add (+) owner (u), group (g) and
top Show real-time view of running other users (o) read (r) permis​sions
system to file

chmod 644 file Set file mode to absolute


kill pid Send TERMinate signal to the permission mode 644
process with ID pid Symbolic links
kill -STOP pid or CTRL-Z Send STOP (freeze) signal to the A symbolic links is a file that points to another file or a directory
process ln -s target linkname Create a symbolic link from target
kill -CONT pid CONTinue running the process to linkname
again
kill -INT pid or CTRL-C End process with INTerrupt signal

kill -KILL pid Terminate the process and forcibly


remove it from memory

By [deleted] Published 3rd August, 2020. Sponsored by Readable.com


cheatography.com/deleted- Last updated 3rd August, 2020. Measure your website readability!
124743/ Page 3 of 4. https://readable.com
Linux Basic Commands Cheat Sheet
by [deleted] via cheatography.com/124743/cs/23886/

Archiving and Compre​ssing Files Some subdir​ect​ories in root (cont)

gzip file Compress file to /usr Other bulk of Linux system


file.gz /var Where programs record runtime inform​ation
gunzip file.gz or gzip -d Uncompress /boot Contains kernel boot loader files
file.gz and
/media A base attachment point for removable media
remove the suffix
/opt This may contain additional third-​party
tar cf archiv​e.tar file1 file2 Create (c) an
software
archive name (f)
/vmlinuz Kernel location
archiv​e.tar
or /boot/vmlinuz
contains file1,
file2 The reason that the root directory does not contain the complete
system but other parts stored in /usr is primarily histor​ic—in the
tar xf archiv​e.tar Unpack (x)
past, it was to keep space requir​ements low for the root
archiv​e.tar

tar tf archiv​e.tar List the contents (t)


of archiv​e.tar

gunzip -c file.tar.gz | tar xf - Unpack compressed


zcat file.tar.gz | tar xf - archive file.t​‐
tar zxf file.tar.gz ar.gz

gunzip -c uncomp​resses archive then sends the result to standard


output.
tar xf - uses standard input instead of a given filename.

Some subdir​ect​ories in root

/bin Contains ready-​to-run programs including most of the basic


Linux commands
/dev Contains device files

/etc Core system config​uration directory that contains the user


password, boot, device, networ​king, and other setup files
/home Holds personal direct​ories for regular users

/lib Holds library files

/proc Provices system statistics

/sys Provides a device and system interface

/sbin Place for system management programs

/tmp Storage area for temporary files

By [deleted] Published 3rd August, 2020. Sponsored by Readable.com


cheatography.com/deleted- Last updated 3rd August, 2020. Measure your website readability!
124743/ Page 4 of 4. https://readable.com

You might also like