Some common commands that I can't always remember, but may also be helpful to anyone running linux.
find . -type f -mtime +30 | tr '\n' '\0' | xargs -0 rmfind . -type f -mtime +30 | tr '\n' '\0' | xargs -0 rmu can type help, but it seems to be generally useless. You gotta know the commands.
- ls -alF: like dir on DOS.
- man command - manual pages for command
- tail -n XX filename - the last XX lines of filename. main log is stored at /var/log
- head filename - first XX lines of filename
- ps -A - to see all processes by all users (-a for all by your user, without subcommand to get just your shell). use
ps -aux
to list all the running processes. ps pid
where pid
is the Process ID (found using the previous command, you get additional useless info).
- kill XXX - to kill a process. to get a process ID (XXX), look in /var/run or run ps -A.
/etc/rc.d/init.d
has startup and stop scripts (for RedHat). Or kill pid
. Or kill -f pid
.
-
Problems?: See the /var/log/messages
file. Use tail -n XX /var/log/messages
to see the last XX lines of the logfile. I've also setup an alias command for logtail and loghead for 25 lines each.
Managing Users and Groups
- id username - shows info on the username including groups, etc.
- groups username - shows info on the groups belonging to. similar to id
- useradd, userdel, usermod - manages users
- groupadd, groupdel, groupmod - manages groups
- passwd - update a user's authentication token(s)
- last - shows the last X users logged into the server; can use last -f <filename> to see others previous. lastb shows the last bad login attempts (if setup).
Managing Applications: Install, Uninstall, Add, Remove, Update Programs, Apps
RPM and YUM are the tools.
Install packages using YUM (command cheatsheet) | Yum and RPM Tricks | Install RPM Packages Using YUM |
- list:
yum list | grep searchterm
- install:
yum install pkg-name
VI/VIM Commands
- :help - open help file (Ctrl-] to surf; Ctrl-T or -O to go back); :q to close help file and return to editor
- :w - write
- :q - quit; :q! quit without saving
- :wq - write and quit
- u - undo
- Ctrl-R or :red - redo
- /pattern - highlight all matching pattern (regex)
- /pattern/x - jump to xth match
- / - move to next match
- ? - move to previous match
- :[range]s/pattern/string/[g][c] - replace pattern with string; g is global; c requires confirmation; a range of 1,$ will do whole file
- i - insert (before cursor)
- a - append (after cursor)
- x - delete character
- dd - delete line
- . - repeat command
- N yy - yank N lines into register
- :reg - shows registers
VIM Configurations:
First my success steps. Below that, the issues I ran into getting there.
My preferences:
- colorscheme: vividchalk
- tab stop of 4 char
Notes:
- user directory ~/.vimrc (contains colors, syntax, and plugin directories
- Script for quick switching of colors (note: doesn't get the user colors)
- can't find a comment method for .vimrc file
My .vimrc file:
- syntax enable
- colorscheme vividchalk
- set tabstop=4
- source ~/.vim/plugin/setcolors.vim
Problems:
Short story: make sure that vim-enhanced is installed
- Syntax Color - I struggled and struggled to get colors working. I read all sorts of things, most the same (the .vimrc commands above). I tried all the extra commands to no avail. I never really saw the suggestion that you need to make sure have have vim-enhanced installed; vim-minimal is not enough. And there are dependencies, of course. I figured it out using "rpm -qa | grep vim" command which showed only vim-minimal. Installed errored out on dependencies and once those were installed, it all worked solid.
- VIM location: I found that whereis and which didn't give expected results. I'd get a pointer to the manual page (and the vim command was showing as vi in /usr/bin, running it showed it was actually vim). What you should see is:
vim: /usr/bin/vim /usr/share/vim /usr/share/man/man1/vim.1.gz
Find
Part of Findutils: Website | Documentation
Finding and fixing permissions for files/directories:
find . -type f -not -perm 644 | xargs chmod 644
find . -type d -not -perm 755 | xargs chmod 755
Find files/directories older than 30 days/empty and delete them (tr is to add null separator):
find . -type f -mtime +30 | tr '\n' '\0' | xargs -0 rm
find . -type d -empty | tr '\n' '\0' | xargs -0 rmdir