Remove files older than....
find ./ -type f -mtime +1095 -exec rm {} \;
(note: mtime = # of days)
Remove files based on text (even in subdirectories)...
grep "^From: whatever you're looking for" -lr . | xargs rm -f
NB: the caret indicates the start of a line.
find
find -type
-f (file) find ~/Documents -type f -name "foo.odt"
-d (directory)
-l (symbolic links)
find -size
n exact size
+n larger than
-n less than
You can also use logical operations like -and, -or and -not.
NB: use the which command to find binaries and whereis for their locations.
tree
instead of ls, use tree.
tree
-L N go only N directories deep
-D show last modification time
-h show size
tar
tar xzf [filename]
x = extract
z = unzip
f = the following file
tar -tf [filename]
t = list contents
tar czf [tarfile] [dir w/files] : i.e., tar czf Extras.tar.gz ./Extras
archive a directory of files
Copying
To copy a directory structure:
find [directory] -type d | cpio -dumpl [directory]
Or which should keep all permissions:
find . -type d | cpio -pdvm destdir
To copy items based on date:
find ./ -type f ! -mtime -2 -exec mv {} ../ \;
[this particular command moves files that are older than yesterday and preserves time stamps]
To copy an entire drive structure with permissions, etc. (-a is archive thereby preserving permissions, links, user and group id's, --progress shows status, --partial helps in the event of interruption)
rsync -av --progress --partial [from] [to]
To remove commented out lines and save to a new file:
cat old.file | grep -v "#" > new.file
Then to remove any blank lines, use vi and issue the following command:
:%s/^\n\{1}//
To merely view a file with all commented out text and blank lines removed:
sed '/^#/d' new.file | sed '/^$/d'
In order to get a listing of all files related to a package
>dpkg -L [name of package]
Linux Centralized Login
> apt-get install libnss-ldap libpam-ldap
Reply default to all prompts, when installing above packages.
> Copy the contents of /etc/libnss-ldap.conf and /etc/pam-ldap.conf from Seabass to new computer.
> Edit /etc/nnsswitch.conf and add ldap to the end of the first 3 lines.
> Check that the packages have been installed by issuing the command nscd.
> Go to the directory /etc/pam.d/ and copy the contents of any one such file/service on Seabass and use it for all those you wish to use on this computer.
Add Workstation to Samba Domain Server
Add to /etc/passwd file on Atlantica name of the new workstation.
Then issue command on Atlantica: smbpasswd -a -m [nameofnewworkstation].
Then on the new workstation issue the command: net join -S atlantica
Specifically for XP:
To join a domain in XP two changes to the system registry must be made. Here are the necessary changes:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters]
(This is the location in the registry)
"requiresignorseal"=dword:00000000
(This parameter was originally set to 1)
"signsecurechannel"=dword:00000000
(This parameter was originally set to 1)
Customize the shell
If, say, you wish to have the '-i' option permanently applied to commands like cp, rm and mv, then add the following lines to ~.tcshrc
alias cp cp -i \\!\*
alias mv mv -i \\!\*
alias rm rm -i \\!\*
If you want to enable a trash command then add:
alias trash mv \\!\* ~/.Trash
Maildir structure when adding user
In order to automatically create a Maildir directory structure when adding users do the following to the /etc/skel/ directory:
maildirmake Maildir
maildirmake -f Sent Maildir
maildirmake -f Drafts Maildir
maildirmake -f Junk Maildir
maildirmake -f Trash Maildir
Set Permissions Recursively
For directories:
find /path -type d -exec chmod 770 {} \;
For files:
find /path -type f -exec chmod 660 {} \;
Zero out an HD
dd if=/dev/zero of=/dev/[device]
nmap
nmap -sT -p[port] -PT [ipaddress]
nmap -p[port] [ipaddress]
ssh
X11 Forwarding
In order to permit X11 Forwarding, edit the X11Forwarding paramtere in the /etc/ssh/sshd_config file to yes.
Deny Users
In order to prevent a user from being able to ssh into a server, you can add the username to DenyUsers parameter in the /etc/ssh/sshd_config file or use the AllowUser or AllowGroup parameters.
Enable passwordless ssh
On the computer you'll be ssh-ing from generate ssh keys:
cd ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa
(no password)
Then from same computer transfer the keys to the client:
ssh-copy-id <username>@<host>