Linux Command
Linux Command
netstat -r -v print network information, sed stream editor csh, tcsh C shell cal print calender
routing and connections
pico simple editor perl Practical Extraction and Report export assign or remove environment
telnet user interface to the TELNET Language variable
protocol
source [file] load any functions file into the ` [command] backquote, execute command
tcpdump dump network traffic Directory Utilities current shell, requires the file
to be executable date -d print formatted date
ssh -i openSSH client
mkdir create a directory $[variable] if set, access the variable
ping -c print routing packet trace to
host network rmdir remove a directory
Ctrl + C Kill process running in the id See details about the mkdir [directory_name] Create a new directory. uname -r Show system information ps List active processes.
terminal. active users. via uname command.
rm [file_name] Remove a file. pstree Show processes in a tree-
Ctrl + Z Stop the current process. last Show the last system uname -a See kernel release like diagram.
The process can be logins. rm -r [directory_name] Remove a directory information.
resumed in the foreground recursively. pmap Display a memory usage
with fg or in the who Display who is currently uptime Display how long the map of processes.
background with bg. logged into the system. rm -rf [directory_name] Recursively remove a system has been running,
directory without requiring including the load average. top See all running processes.
Ctrl + W Cut one word before the w Show which users confirmation.
cursor and add it to the are logged in and their hostname View system hostname. htop Interactive and colorful
clipboard. activity. cp [source_file] Copy the contents of one process viewer.
[destination_file] file to another file. hostname -i Show the IP address of the
Ctrl + U Cut part of the line before finger [user_name] Show user information. system. kill [process_id] Terminate a Linux
the cursor and add it to the cp -r [source_directory] Recursively copy a process under a given ID.
clipboard. sudo useradd Create a new user account. [destination_directory] directory to a second last reboot List system reboot history.
[user_name] directory. pkill [process_name] Terminate a process under
Ctrl + K Cut part of the line after the date See current time and date. a specific name.
cursor and add it to the sudo adduser Create a new user account mv [source_file] Move or rename files or
clipboard. [user_name] through the adduser [destination_file] directories. timedatectl Query and change killall [label] Terminate all processes with
command interface. the system clock. a given label.
Ctrl + Y Paste from clipboard. ln -s [path]/[file_name] Create a symbolic link to a
sudo userdel [user_name] Delete a user account. [link_name] file. cal Show current calendar prgrep [keyword] List processes based on the
Ctrl + R Recall the last command (month and day). provided keyword.
that matches the provided sudo usermod -aG Modify user touch [file_name] Create a new file.
characters. [group_name] information (add a user to w List logged-in users. pidof [process_name] Show the PID of a process.
[user_name] a group). cat [file_name] Show the contents of a file.
Ctrl + O Run the previously recalled whoami See which user you are bg List and resume stopped
command. passwd Change the current user's cat [source_file] >> Append file contents to using. jobs in the background.
sudo passwd [user_name] or another user's [destination_file] another file.
Ctrl + G Exit command history password. finger [user_name] Show information about a Bring the most recently
without running a head [file_name] Show the first ten lines of a particular user. fg suspended job to the
command. sudo groupadd Add a new group. file. foreground.
[group_name] ulimit [flags] [limit] View or limit system
clear Clear the terminal screen. tail [file_name] Show the last ten lines of a resource amounts. fg [job] Bring a particular job to the
sudo groupdel Delete a group. file. foreground.
!! Run the last command [group_name] shutdown [hh:mm] Schedule a system
again. more [file_name] Display contents of a file shutdown. lsof List files opened by running
sudo groupmod -n Modify a user group page by page. processes.
exit Log out of the current [new_name] [old_name] (change group name). shutdown now Shut down the system
session. less [file_name] Show the contents of a file immediately. trap "[commands]" Catch a system error
sudo [command] Temporarily elevate user with navigation. [signal] signal in a shell script.
privileges to superuser or modprobe Add a new kernel module. Executes provided
Searching root. nano [file_name] Open or create a file using [module_name] commands when the signal
the nano text editor. is caught.
find [path] -name Find files and su - [user_name] Switch the user account or dmesg Show bootup messages.
[search_pattern] directories that match the become a superuser. vi [file_name] Open or create a file using wait Pause the terminal or a
specified pattern in a vim [file_name] the Vi/Vim text editor. Bash script until a running
specified location. chgrp [group_name] [file/ Change file or directory Network process is completed.
directory] group. gpg -c [file_name] Encrypt a file.
find [path] -size [+100M] See files and directories ip addr show List IP addresses and nohup [command] & Run a Linux process in the
larger than a specified size gpg [file_name].gpg Decrypt an network interfaces. background.
in a directory. SSH Login encrypted .gpg file.
ip address add Assign an IP address to
grep [search_pattern] Search for a specific ssh [user_name]@[host] Connect to a remote wc -w [file_name] Show the number of [IP_address] interface eth0.
Hardware Information
[file_name] pattern in a file with grep. host as a user via SSH. words, lines, and bytes in a
file. ifconfig Display IP addresses of all lscpu See CPU information.
grep -r [search_pattern] Recursively search for a ssh [host] Securely connect to a network interfaces.
[directory_name] pattern in a directory. host via SSH default ls | xargs wc List the number of lines/ lsblk See information about
port 22. words/characters in each ping [remote_host] Ping remote host. block devices.
locate [name] Locate all files and file in a directory.
directories related to a ssh -p [port] Connect to the host netstat -pnltu See active (listening) ports lspci -tv Show PCI devices in a tree-
particular name. [user_name]@[host] using a particular port. cut -d [delimiter] Cut a section of a file and with the netstat command. like diagram.
[file_name] print the result to standard
which [command] Search the command ssh-keygen Generate SSH key pairs. output. netstat -tuln Show TCP and UDP ports lsusb -tv Display USB devices in a
path in and their programs. tree-like diagram.
the $PATH environment sudo service sshd start Start SSH [data] | cut -d [delimiter] Cut a section of piped data
variable. server daemon. and print the result to whois [domain_name] Display more information lshw List hardware configuration
standard output. about a domain. information.
whereis [command] Find the source, binary, scp [file_name] Securely copy
and manual page for a [user_name]@[host]:[rem files between local and shred -u [file_name] Overwrite a file to prevent dig [domain_name] Show DNS information cat /proc/cpuinfo Show detailed CPU
command. ote_path] remote systems via SSH. its recovery, then delete it. about a domain using information.
the dig command.
awk '[search_pattern] Print all lines matching a sftp [user_name]@[host] Interactive file transfer diff [first_file] Compare two files and cat /proc/meminfo View detailed system
{print $0}' [file_name] pattern in a file. See also over encrypted SSH [second_file] display differences. dig -x [domain_name] Do a reverse DNS lookup memory information.
the gawk command, the session on the domain.
GNU version of awk. using SFTP protocol. source [file_name] Read and execute the file cat /proc/mounts See mounted file systems.
content in the current shell. dig -x [IP_address] Do a reverse DNS lookup of
sed 's/[old_text]/ Find and replace text in a telnet [host] Connect to the host an IP address. free -h Display free and used
[new_text]/' [file_name] specified file. via Telnet default port [command] | tee Store the command output memory.
23. [file_name] >/dev/null in a file and skip the host [domain_name] Perform an IP lookup for a
terminal output. domain. sudo dmidecode Show hardware information
Directory Navigation from the BIOS.
File Permissions Disk Usage hostname -I Show the local IP address
ls List files and directories in hdparm -i /dev/ Display disk data
the current directory. nslookup Receive information about [device_name] information.
chmod 777 [file_name] Assign read, write, and df -h Check free and used
space on mounted [domain_name] an internet domain.
execute file permission to hdparm -tT /dev/ Conduct a read speed test
ls -a List all files and directories everyone (rwxrwxrwx). systems.
in the current directory . [device_name] on the device/disk.
(shows hidden files).
File Compression
chmod 755 [file_name] Give read, write, and df -i Show free inodes on
badblocks -s /dev/ Test for unreadable blocks
execute permission to mounted file systems.
ls -l List files and directories in tar cf [archive.tar] [file/ Archive an existing file or [device_name] on the device/disk.
owner, and read and
long format. fdisk -l Display disk partitions, directory] directory.
execute permission to fsck /dev/[device_name] Run a disk check on an
group and others sizes, and types with the
pwd Show the directory you tar xf [archive.tar] Extract an archived file. unmounted disk or
(rwxr-xr-x). command.
are currently working in. partition.
du -ah See disk usage for all files tar czf [archive.tar.gz] Create a .gz compressed
chmod 766 [file_name] Assign full permission to
cd Change and directories. tar archive.
the owner, and read and Shell Commands
cd ~ directory to $HOME. write permission to the
du -sh Show disk usage of the gzip [file_name] Compress or
group and others
cd .. Move up one directory current directory. gunzip [file_name.gz] decompress .gz files. alias [alias- Create an alias for a
(rwxrw-rw-).
level. name]='[command]' command.
mount Show currently mounted bzip2 [file_name] Compress or decompress
chown [user_name] Change the ownership of
cd - Change to the previous file systems. bunzip2 [file_name.bz2] .bz2 files. watch -n [interval-in- Set a custom interval to
[file_name] a file with chown
directory. command. seconds] [command] run a user-defined
command.
cd [directory_path] Change location to a
findmnt Display target mount File Transfer
chown Change the owner and point for all file systems.
specified directory. [user_name]:[group_nam group ownership of a file. sleep [time-interval] && Postpone the
scp [source_file] Copy a file to a server [command] execution of a command.
e] [file_name] mount [device_path] Mount a device.
dirs Show current directory [user]@[remote_host]:[de directory securely.
[mount_point]
stack. stination_path] at [hh:mm] Create a job to be
Packages (Red Hat, CentOS, Fedora) executed at a certain time
Packages (Universal) rsync -a Synchronize the contents (Ctrl+D to exit prompt
Packages (Debian/Ubuntu) [source_directory] of a directory with a after command).
sudo yum install Install a package using [user]@[remote_host]:[de backup directory.
[package_name] the YUM package tar zxvf [file_name.tar.gz] Install software
sudo apt-get install Install an APT package stination_directory] man [command] Display a built-in
manager. cd [extracted_directory] from source code.
[package_name] using the apt-get manual for a command.
./configure make
package utility. wget [link] Download files from FTP
yum search [keyword] Find a package in the make install
or web servers. history Print the command
YUM repositories based
sudo apt install Install an APT package history used in the
on the provided keyword. sudo snap install Install a Snap package.
[package_name] using a newer APT curl -O [link] Transfer data to or from a terminal.
[package_name]
package manager. server with various
yum list installed List all packages installed protocols.
with YUM. sudo snap find [keyword] Search for a package in Variables
apt search [keyword] Search for a package in
the Snap store.
the APT repositories. ftp [remote_host] Transfer files between
yum info [package_name] Show package local and remote systems
sudo snap list List installed Snap let Assign an integer value to
information for a interactively using FTP.
apt list List packages installed "[variable_name]=[value]" a variable.
package. packages.
with APT.
sftp Securely transfer between export [variable_name] Export a Bash variable.
sudo dnf install Install a package using flatpak install Install a Flatpak package.
apt show Show information about a [user]@[remote_host] local and remote hosts
[package_name] the DNF package [package_name]
[package_name] package. using SFTP. declare [variable-name]= Declare a Bash variable.
manager.
flatpak search [keyword] Search for a Flatpak "[value]"
sudo dpkg -i Install a .deb package with
sudo rpm -i Install a .rpm package application in repositories.
[package_name.deb] the Debian package set List the names of all the
[package_name.rpm] from a local file.
manager. shell variables and
flatpak list List installed Flatpack
packages. functions.
sudo dpkg -l List packages installed
with dpkg. unset [variable_name] Remove an environment
variable.
5
Linux can also be used as your day to day computer. I
use macOS because I really enjoy the applications,
the design and I also used to be an iOS and Mac apps
developer, but before using it I used Linux as my main
computer Operating System.
6
If you use a Mac you need to know that under the
hood macOS is a UNIX Operating System, and it
shares a lot of the same ideas and software that a
GNU/Linux system uses, because GNU/Linux is a free
alternative to UNIX.
But the vast majority of the time you will run a Linux
computer in the cloud via a VPS (Virtual Private
Server) like DigitalOcean.
7
There are many different kind of shells. This post
focuses on Unix shells, the ones that you will find
commonly on Linux and macOS computers.
8
man
The first command I want to introduce is a command
that will help you understand all the other commands.
9
This is not a substitute for man , but a handy tool to
avoid losing yourself in the huge amount of
information present in a man page. Then you can use
the man page to explore all the different options and
parameters you can use on a command.
10
ls
Inside a folder you can list all the files that the folder
contains using the ls command:
ls
ls /bin
ls -al /bin
11
compared to the plain ls , this returns much more
information.
12
cd
Once you have a folder, you can move into it using the
cd command. cd means change directory. You
invoke it specifying a folder to move into. You can
specify a folder name, or an entire path.
Example:
mkdir fruits
cd fruits
mkdir fruits
mkdir cars
cd fruits
cd ../cars
You can also use absolute paths, which start from the
root folder / :
13
cd /etc
14
pwd
Whenever you feel lost in the filesystem, call the pwd
pwd
15
mkdir
You create folders using the mkdir command:
mkdir fruits
mkdir -p fruits/apples
16
rmdir
Just as you can create a folder using mkdir , you can
delete a folder using rmdir :
mkdir fruits
rmdir fruits
17
mv
Once you have a file, you can move it around using
the mv command. You specify the file current path,
and its new path:
touch test
mv pear new_pear
touch pear
touch apple
mkdir fruits
mv pear apple fruits #pear and apple moved to the fr
18
cp
You can copy a file using the cp command:
touch test
cp apple another_apple
mkdir fruits
cp -r fruits cars
19
open
The open command lets you open a file using this
syntax:
open <filename>
open .
20
touch
You can create an empty file using the touch
command:
touch apple
21
find
The find command can be used to find files or
folders matching a particular search pattern. It
searches recursively.
Find all the files under the current tree that have the
.js extension and print the relative path of each file
matching:
22
Find directories under the current tree matching the
name "node_modules" or 'public':
23
You can execute a command on each result of the
search. In this example we run cat to print the file
content:
24
ln
The ln command is part of the Linux file system
commands.
Hard links
Hard links are rarely used. They have a few
limitations: you can't link to directories, and you can't
link to external filesystems (disks).
ln <original> <link>
ln recipes.txt newrecipes.txt
25
Now any time you edit any of those files, the content
will be updated for both.
If you delete the original file, the link will still contain
the original file content, as that's not removed until
there is one hard link pointing to it.
Soft links
Soft links are different. They are more powerful as you
can link to other filesystems and to directories, but
when the original is removed, the link will be broken.
26
ln -s <original> <link>
ln -s recipes.txt newrecipes.txt
27
gzip
You can compress a file using the gzip compression
protocol named LZ77 using the gzip command.
gzip filename
gzip -k filename
option:
28
gzip -1 filename
gzip -r a_folder
gzip -d filename.gz
29
gunzip
The gunzip command is basically equivalent to the
gzip command, except the -d option is always
enabled by default.
gunzip filename.gz
30
tar
The tar command is used to create an archive,
grouping multiple files in a single file.
31
tar is often used to create a compressed archive,
gzipping the archive.
32
alias
It's common to always run a program with a set of
options you like using.
33
alias ll='ls -al'
34
alias lsthis="ls $PWD"
alias lscurrent='ls $PWD'
lists the files in the new folder, lsthis still lists the
files in the folder you were when you defined the alias.
35
cat
Similar to tail in some way, we have cat . Except
cat can also add content to a file, and this makes it
super powerful.
cat file
cat -n file1
36
You can only add a number to non-blank lines using -
37
less
The less command is one I use a lot. It shows you
the content stored inside a file, in a nice and
interactive UI.
38
This command just visualises the file's content. You
can directly open an editor by pressing v . It will use
the system editor, which in most cases is vim .
<filename> command.
39
tail
The best use case of tail in my opinion is when called
with the -f option. It opens the file at the end, and
watches for file changes. Any time there is new
content in the file, it is printed in the window. This is
great for watching log files, for example:
tail -f /var/log/system.log
tail -n 10 <filename>
40
wc
The wc command gives us useful information about
a file or input it receives via pipes.
ls -al | wc
6 47 284
wc -l test.txt
wc -w test.txt
wc -c test.txt
41
Bytes in ASCII charsets equate to characters, but with
non-ASCII charsets, the number of characters might
differ because some characters might take multiple
bytes, for example this happens in Unicode.
wc -m test.txt
42
grep
The grep command is a very useful tool, that when
you master will help you tremendously in your day to
day.
43
One very useful thing is to tell grep to print 2 lines
before, and 2 lines after the matched line, to give us
more context. That's done using the -C option, which
accepts a number of lines:
44
Another thing you might find very useful is to invert the
result, excluding the lines that match a particular
string, using the -v option:
45
sort
Suppose you have a text file which contains the
names of dogs:
46
Sorting by default is case sensitive, and alphabetic.
Use the --ignore-case option to sort case insensitive,
and the -n option to sort using a numeric order.
47
sort does not just works on files, as many UNIX
commands it also works with pipes, so you can use on
the output of another command, for example you can
order the files returned by ls with:
ls | sort
48
49
uniq
uniq is a command useful to sort lines of text.
You can get those lines from a file, or using pipes from
the output of another command:
uniq dogs.txt
ls | uniq
This implies that you will most likely use it along with
sort :
50
You can tell it to only display duplicate lines, for
example, with the -d option:
51
You can use the -u option to only display non-
duplicate lines:
c option:
52
Use the special combination:
53
diff
diff is a handy command. Suppose you have 2
files, which contain almost the same information, but
you can't find the difference between the two.
diff will process the files and will tell you what's the
difference.
54
If you invert the order of the files, it will tell you that the
second file is missing line 3, whose content is
Vanille :
55
In case you're interested in which files differ, rather
than the content, use the r and q options:
56
57
echo
The echo command does one simple job: it prints to
the output the argument passed to it.
This example:
echo "hello"
58
This is just the start. We can do some nice things
when it comes to interacting with the shell features.
echo *
echo o*
Any valid Bash (or any shell you are using) command
and feature can be used here.
echo ~
59
Note that whitespace is not preserved by default. You
need to wrap the command in double quotes to do so:
echo {1..5}
60
chown
Every file/directory in an Operating System like Linux
or macOS (and every UNIX systems in general) has
an owner.
command:
Like this:
61
It's rather common to have the need to change the
ownership of a directory, and recursively all the files
contained, plus all the subdirectories and the files
contained in them, too.
Example:
You can also just change the group of a file using the
chgrp command:
62
chmod
Every file in the Linux / macOS Operating Systems
(and UNIX systems in general) has 3 permissions:
Read, write, execute.
The weird strings you see on each file line, like drwxr-
63
The third set represents the permissions of the
everyone else
64
You can apply the same permissions to multiple
personas by adding multiple letters before the + / - :
0 no permissions
1 can execute
2 can write
3 can write, execute
4 can read
5 can read, execute
6 can read, write
7 can read, write and execute
65
chmod 777 filename
chmod 755 filename
chmod 644 filename
66
umask
When you create a file, you don't have to decide
permissions up front. Permissions have defaults.
67
Other users belonging to the same group ( g ) have
read and execution permission, same as all the other
users ( o ).
We can set a new value for the mask setting the value
in numeric format:
umask 002
umask g+r
68
du
The du command will calculate the size of a directory
as a whole:
du
69
The -h option will show a human-readable notation
for sizes, adapting to the size:
70
71
df
The df command is used to get disk usage
information.
72
basename
Suppose you have a path to a file, for example
/Users/flavio/test.txt .
Running
basename /Users/flavio/test.txt
73
dirname
Suppose you have a path to a file, for example
/Users/flavio/test.txt .
Running
dirname /Users/flavio/test.txt
74
ps
Your computer is running, at all times, tons of different
processes.
75
The a option is used to also list other users
processes, not just our own. x shows processes
not linked to any terminal (not initiated by users
through a terminal).
76
You can search for a specific process combining
grep with a pipe, like this:
77
It's common to have + which indicates the process is
in the foreground in its terminal. s means the
process is a session leader.
78
top
A quick guide to the top command, used to list the
processes running in real time
79
Below, the list of processes taking the most memory
and CPU is constantly updated.
top -o mem
80
kill
Linux processes can receive signals and react to
them.
kill <PID>
81
INT means interrupt, and it sends the same signal
used when we press ctrl-C in the terminal, which
usually terminates the process.
82
killall
Similar to the kill command, killall instead of
sending a signal to a specific process id will send the
signal to multiple processes at once.
killall <name>
You can specify the signal, like with kill (and check
the kill tutorial to read more about the specific
kinds of signals we can send), for example:
83
jobs
When we run a command in Linux / macOS, we can
set it to run in the background using the & symbol
after the command. For example we can run top in
the background:
top &
Z .
84
bg
When a command is running you can suspend it using
ctrl-Z .
85
fg
When a command is running in the background,
because you started it with & at the end (example:
top & or because you put it in the background with
the bg command, you can put it to the foreground
using fg .
Running
fg
86
87
type
A command can be one of those 4 types:
an executable
a shell built-in program
a shell function
an alias
This is Zsh:
88
This is Fish:
89
One of the most interesting things here is that for
aliases it will tell you what is aliasing to. You can see
the ll alias, in the case of Bash and Zsh, but Fish
provides it by default, so it will tell you it's a built-in
shell function.
90
which
Suppose you have a command you can execute,
because it's in the shell path, but you want to know
where it is located.
91
nohup
Sometimes you have to run a long-lived process on a
remote machine, and then you need to disconnect.
92
xargs
The xargs command is used in a UNIX shell to
convert input from standard input into arguments to a
command.
93
We will channel the output of cat todelete.txt to the
rm command, through xargs .
In this way:
94
The -n option lets you tell xargs to perform one
iteration at a time, so you can individually confirm
them with -p . Here we tell xargs to perform one
iteration at a time with -n1 :
95
vim
vim is a very popular file editor, especially among
programmers. It's actively developed and frequently
updated, and there's a very big community around it.
There's even a Vim conference!
vi test.txt
96
You have to know that Vim has 2 main modes:
Now you can start typing and filling the screen with the
file contents:
97
You can move around the file with the arrow keys, or
using the h - j - k - l keys. h-l for left-right,
j-k for down-up.
Once you are done editing you can press the esc
At this point you can navigate the file, but you can't
add content to it (and be careful which keys you press
as they might be commands).
98
You can save and quit pressing : then w and q :
:wq
and ! : :q!
99
will greatly help you start your vim explorations.
100
emacs
emacs is an awesome editor and it's historically
regarded as the editor for UNIX systems. Famously
vi vs emacs flame wars and heated discussions
caused many unproductive hours for developers
around the world.
101
macOS users, stop a second now. If you are on
Linux there are no problems, but macOS does not
ship applications using GPLv3, and every built-in
UNIX command that has been updated to GPLv3
has not been updated. While there is a little
problem with the commands I listed up to now, in
this case using an emacs version from 2007 is not
exactly the same as using a version with 12 years
of improvements and change. This is not a
problem with Vim, which is up to date. To fix this,
run brew install emacs and running emacs will
use the new version from Homebrew (make sure
you have Homebrew installed)
<filename> :
You can start editing and once you are done, press
ctrl-x followed by ctrl-w . You confirm the folder:
102
and Emacs tell you the file exists, asking you if it
should overwrite it:
103
You can exit Emacs pressing ctrl-x followed by
ctrl-c . Or ctrl-x followed by c (keep ctrl
pressed).
104
nano
nano is a beginner friendly editor.
105
whoami
Type whoami to print the user name currently logged
in to the terminal session:
106
who
The who command displays the users logged in to
the system.
You can see the name of the terminal used, and the
time/day the session was started.
107
The special who am i command will list the current
terminal session details:
108
su
While you're logged in to the terminal shell with one
user, you might have the need to switch to another
user.
su <username>
109
sudo
sudo is commonly used to run a command as root.
110
sudo -u flavio ls /Users/flavio
111
passwd
Users in Linux have a password assigned. You can
change the password using the passwd command.
passwd
112
ping
The ping command pings a specific network host, on
the local network or on the Internet.
113
Not all servers support pinging, in case the requests
times out:
114
traceroute
When you try to reach a host on the Internet, you go
through your home router, then you reach your ISP
network, which in turn goes through its own upstream
network router, and so on, until you finally reach the
host.
Have you ever wanted to know what are the steps that
your packets go through to do that?
You invoke
traceroute <host>
115
Not every router travelled returns us information. In
this case, traceroute prints * * * . Otherwise, we
can see the hostname, the IP address, and some
performance indicator.
traceroute -q 1 flaviocopes.com
116
clear
Type clear to clear all the previous commands that
were ran in the current terminal.
The screen will clear and you will just see the prompt
at the top:
117
history
Every time we run a command, that's memorized in
the history.
history
command.
118
To clear the history, run history -c
119
export
The export command is used to export variables to
child processes.
TEST="test"
120
Then you set chmod u+x script.sh and you execute
this script with ./script.sh , the echo $TEST line will
print nothing!
TEST="test"
export TEST="test"
export PATH=$PATH:/new/path
121
It's common to use export when you create new
variables in this way, but also when you create
variables in the .bash_profile or .bashrc
export -n TEST
122
crontab
Cron jobs are jobs that are scheduled to run at specific
intervals. You might have a command perform
something every hour, or every day, or every 2 weeks.
Or on weekends. They are very powerful, especially
on servers to perform maintenance and automations.
crontab -l
Run
crontab -e
123
By default this opens with the default editor, which is
usually vim . I like nano more, you can use this line
to use a different editor:
EDITOR=nano crontab -e
Now you can add one line for each cron job.
You pick a time interval for the cron job, and you type
the command to execute.
124
I chose to run a script located in
/Users/flavio/test.sh every 12 hours. This is the
crontab line I need to run:
I run crontab -e :
EDITOR=nano crontab -e
to save.
Once this is done, you can see the list of active cron
jobs by running:
crontab -l
125
You can remove a cron job running crontab -e again,
removing the line and exiting the editor:
126
uname
Calling uname without any options will return the
Operating System codename:
127
The n option prints the node network name:
128
On macOS you can also use the sw_vers command
to print more information about the macOS Operating
System. Note that this differs from the Darwin (the
Kernel) version, which above is 19.6.0 .
129
env
The env command can be used to pass environment
variables without setting them on the outer
environment (the current shell).
interface.
option:
program:
130
Try with a simple app.js file with this content:
console.log(process.env.NAME)
console.log(process.env.PATH)
undefined
undefined
flavio
undefined
env
131
it will return a list of the environment variables set, for
example:
HOME=/Users/flavio
LOGNAME=flavio
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/L
PWD=/Users/flavio
SHELL=/usr/local/bin/fish
132
printenv
A quick guide to the printenv command, used to
print the values of environment variables
HOME=/Users/flavio
LOGNAME=flavio
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/L
PWD=/Users/flavio
SHELL=/usr/local/bin/fish
printenv PATH
133
Networking Commands for
DevOps
1.ping - To check the reachability of a host on an Internet
Protocol (IP) network.