Shell Commands and Configuration Guide
Shell Variable
<variable_name>=<value>
echo $<variable_name>
Environment Variables
export <variable_name>
export EDITOR=nano
unset <variable_name>
declare -p <variable_name>
<variable_name>=<value>;export <variable_name>
Aliases
alias ls='ls --color=auto'
unalias
Locale
locale -a
locale -k LC_TIME
export LANG=en_US.UTF-8
localectl set-locale LANG=en_US.UTF-8
Verify changes:
Localectl status
Page 1
Shell Commands and Configuration Guide
Viewing and Setting Time
Date
Set the date:
date -s "2025-01-16"
Set time:
date -s "12:34:56"
View current time zone:
Timedatectl
List all time zones:
timedatectl list-timezones
Change time zone:
timedatectl set-timezone America/New_York
System and User Files
System-wide Files (affect all users):
- /etc/profile: General settings for all users when they log in.
- /etc/bashrc: Shell-specific settings for all users.
User-specific Files (affect only you):
- ~/.bash_profile: Runs when you log in and sets up your environment.
- ~/.bashrc: Runs every time you open a new terminal.
- ~/.bash_logout: Runs when you log out and can do clean-up tasks.
Page 2
Shell Commands and Configuration Guide
Order of Execution
When you log in or open a terminal, these files run in this order:
1. /etc/profile
2. ~/.bash_profile
3. ~/.bashrc
4. /etc/bashrc
Example: Setting an Alias
Permanent Shortcut:
- Open ~/.bashrc using: nano ~/.bashrc.
- Add: alias ll="ls -al".
- Save and exit.
- Run: source ~/.bashrc to apply your changes immediately.
Processes and Child Shells
1. Using ps and ps -f:
Redirection and Pipes
Redirecting Input (<):
$ cat < /etc/hosts
Heredocs (<<):
$ cat << END
Page 3
Shell Commands and Configuration Guide
Line 1
Line 2
END
Herestrings (<<<):
$ cat <<< "Hello, World!"
Redirecting Output (> and >>):
$ who > whofile
$ pwd >> whofile
Redirecting Errors (2> and 2>>):
$ ls /etc /nonexistent 2> errorfile
$ command > file 2>&1
Pipes (|):
$ cat file1 | grep "search-term"
The tee Command:
$ cat /etc/hosts | tee filea
Key Files for User and Group Information
/etc/passwd
/etc/shadow
Page 4
Shell Commands and Configuration Guide
/etc/group
Common Directories
/ (root)
/bin
/etc
/usr
/var
/home
/tmp
Navigating Directories
pwd: Displays current directory
cd: Change directory
Viewing Files
cat <filename>
less <filename>
more <filename>
head -n <number> <filename>
tail -n <number> <filename>
tail -f <filename>
Page 5
Shell Commands and Configuration Guide
Deleting Files and Directories
rm <filename>
rmdir <directory>
Using grep to Search
egrep <options> <string> <file(s)>
Page 6