Coding Knowledge Center
Linux/Unix
Administration (visudo) |
visudo (edit /etc/sudoers)
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL) ALL
steved ALL=(ALL) ALL
%admin ALL=(ALL) ALL
Add users you'd like to have sudo access. Add groups prefixed w/ a % sign.
apropos |
> apropos print
Searches through man pages for relavent topics regarding the word print.
cat |
> cat > file.txt
Creates the file named "file.txt" and accepts the following lines as file contents. Press CTRL+d to exit data entry.
cut |
> cut -d: -f5 file.txt
Cuts data from the fifth field a colon delimited file.
IRC (Irssi - commands) |
esc, n - Scroll screen up (do for each scroll needed)
esc, p - Scroll screen down (do for each scroll needed)
ALT + # - Switches to window with respective number.
Irssi Commands
man |
1) man -k list
2) man -S 5 passwd
1) Searches man pages for references to 'list'. Also see the 'apropos' command.
2) Displays the fifth man page section for the passwd command.
Permissions (01. Example) |
A) ---------- : file with all access denied
B) drwxrwxrwx : directory with all access allowed
C) ----------
1234567890
Example A shows a file's permissions with all access denied.
Example B shows a directory's permission with all access allowed
Example C lays out each bit with a number underneath for reference in the following descriptions.
Permissions (02. File type codes - bit 1) |
- - normal file
d - directory
l - symbolic link
p - named pipe
s - socket
b - block device
c - character device
The first permission bit of a file is represented with one of the above characters and designates the inode type.
Permissions (03. bit codes - bits 2-10) |
r = 4 (read)
w = 2 (write)
x = 1 (execute)
- = 0 (no permissions)
Each permission type is assigned a value 4, 2, 1 or 0
Permissions (04. bit groupings) |
user : -rwx------ (bits 2-4)
group : ----rwx--- (bits 5-7)
other : -------rwx (bits 8-10)
The first permission bit (indicated by 1) is represented with one of the above characters and designates the inode type.
Permissions (05. SUID - bit 4) |
s - suid code w/ user execute permissions
-rwsrwxrwx
S - suid code w/o user execute permissions
-rwSrwxrwx
Sometimes it necessary to run a program as the owner of the program. Setting the SUID gives the ability to setup a program to be run as if the owner were running it. A lower case "s" indicates that the owner has executable permissions as well. An uppercase "S" implies the the user does not have executable permissions.
Permissions (06. SGID - bit 7) |
s - sgid code w/ group execute permissions
-rwxrwsrwx
S - sgid code w/o group execute permissions
-rwxrwSrwx
Sometimes it necessary to run a program as the group who owns the program. Setting the SGID gives the ability to setup a program to be run as if the group owner were running it. A lower case "s" indicates that the group has executable permissions as well. An uppercase "S" implies the the group does not have executable permissions.
Permissions (07. Sticky Bit - bit 10) |
t/T - sticky bit
-rwxrwxrwt
-rwxrwxrwT
The first permission bit (indicated by 1) is represented with one of the above characters and designates the inode type.
Permissions (08. chmod) |
chmod 777 file1 OR chmod ugo+rwx file1
Here are two different ways to perform the same permission change.
Permissions (09. chmod - find) |
1) find ./ -user steved -type f -print | xargs chmod 666
find ./ -user steved -type d -print -exec chmod 666 {} \;
2) find ./ -user steved -type d -print | xargs chmod 777
find ./ -user steved -type d -print -exec chmod 777 {} \;
1) These commands find all of the files, in the present working directory, owned by steved and changes their permissions to 666. Both commands do the same thing.
2) These commands find all of the directories, in the present working directory, owned by steved and changes their permissions to 777. Both commands do the same thing.
Permissions (10. chown) |
1) chown steved file1
2) find ./ -user root | xargs chown steved
1) This command changes ownership of the file "file1" to steved.
2) This command finds all of the nodes, in the present working directory, owned by root and changes their ownership to the user steved.
Redirection (operators) |
- Creates a new file containing standard output. If the file exists then its overwritten.
>> - Appends standard output to the file. If the file does not exist it is created.
2> - Creates a new file containing standard error. If the file exists then its overwritten.
2>> - Appends standard error to the file. If the file does not exist it is created.
&> - Creates a new file containing both standard output and standard error. If the file exists then its overwritten.
< - Uses the contents of the specified file as standard input to the receiving program.
<< - Uses the contents of the following lines as standard input to the receiving program.
<> - Uses the contents of the specified file as standard input and standard output.
Operators used in redirection statements.
Snippet (find) |
find . -type d -exec chmod 775 {} \;
find . -type f -exec chmod 664 {} \;
find . -user root | xargs chown steved
find /usr/local/src -exec grep -s "mytext" {} \; -exec echo " " {} "\n" \;
Various find commands
Snippets (arch) |
> arch
i386
Various arch commands
Snippets (bc) |
bc -l
Various bc commands
Snippets (echo) |
> echo {con,pre}{sent,fer}{s,ed}
consents consented confers confered presents presented prefers prefered
Various echo commands
Snippets (id) |
> id
uid=501(steved) gid=20(staff) groups=20(staff),98(_lpadmin),81(_appserveradm),
101(com.apple.sharepoint.group.1),79(_appserverusr),80(admin)
Various id commands
Snippets (kill) |
killall -HUP inetd
kill -stop PID
kill -cont PID
Various kill commands
Snippets (rsync) |
rsync -avz --no-perms /the/original/path/subdir -e ssh login@server:/the/original/path
Various rsync commands
VI (Commands) |
Commands:
k - up
j - down
h - left
l - right
^ - beginning of line
$ - end of line
1G OR :0 - goto start of file
G OR :$ - goto end of file
nG - goto line #
a - append here
A - append at end of line
J - join 2 lines
i - insert here
I - insert at start of line
R - overstrike
o - open line below current line
O - open line above current line
p - put yanked line below current line
u - undeo last change
U - undo all changes
x - delete character
yy - yank line
:%s/str1/str2/g - substitute string str1 to string str2 globally
/pattern - search pattern
n - repeat previous search
N - repeat previous search in reverse
n1,n2tn3 - copy lines from line n1-n2 and put after line n3
n1,n2mn3 - move lines from line n1-n2 and put after line n3
:q - quit
:q! - quit w/o save
:x OR :wq - save & quit
VI Commands
VI (Files) |
~/.exrc
~/.vimrc
Files used for vi settings.
VI (Modes) |
insert mode
command mode
ex mode
VI modes.
VI (Settings) |
:set number - turns on line numbering
:set nonumber - turns off line numbering
Command mode settings.
VIM (settings - vimrc) |
autocmd BufReadPost * // open at last line
Configures vim to open files at the last line it was on before closed.