Various Commands
Linux commands
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
ext2 > ext3
Create a journal for the partition:
tune2fs -j /dev/hdaX
Edit the filesystem name in /etc/fstab for that partition.
Then remount the partition.
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 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]
In order to reset the terminal if it is fucking up
>reset
or
>stty sane
apt
When updating:
apt-get update
apt-get check (to verify that your system and apt are working correctly w/out broken dependencies. And then!)
apt-get upgrade
apt-get -u install (if you want to first see the potential upgrades)
Build an rpm
apt-get --compile source [packagename]
When removing
apt-get --purge remove [packagename] (if you want to remove EVERYTHING)
Installed packages
apt-cache [packagename]
apt-cache search [pattern]
apt-cache showpkg [packagename]
apt-cache show [packagename] (complete information about a package)
Packages are left in [/sw]/var/cache/apt/archives/
in order to clean this up issue the command apt-get clean (or apt-get autoclean in order to leave latest versions).
GPG Authentication
gpg --keyserver wwwkeys.eu.pgp.net --recv-keys 946AA6E18722E71E
gpg --armor --export 946AA6E18722E71E | apt-key add -
Installing apps from Sid
First, add 'deb' lines for stable, testing and unstable to your sources.list. All of them. I have them in the above order, but I don't know if that is necessary.
Second, create a file /etc/apt/preferences with these lines (excluding the lines with the hyphens):
-------------------
Package: *
Pin: release a=testing
Pin-Priority: 900
Package: *
Pin: release a=unstable
Pin-Priority: 50
-------------------
This declares your preference for testing over unstable.
Now run "apt-get update" to update all the lists.
If you now do "apt-get install package" and package is in testing, you will get that. If it is not in testing, but in unstable you will get nothing because your preference for unstable is too low.
At last the interesting part. apt-get has a -t option that alters the priorities set in your /etc/apt/preferences. If you do "apt-get -t unstable install package", unstable will have a priority of 990, which is above the default 900 for testing, so now unstable is your preferred release, but just for that run of apt-get. An install might drag in a lot of other stuff from unstable, so you might want to try "apt-get -s -t unstable install package" before actually doing it.
As an example, evolution is only in unstable. With the above setup, "apt-get install evolution" will not install anything, but "apt-get -t unstable install evolution" will install evolution and a whole slate of needed packages.
You can see how far you are from sid with "apt-get -s -t unstable dist-upgrade".
Distribution Upgrade
Edit /etc/apt/sources.list
apt-get update
apt-get install apt dpkg apt-utils
apt-get dist-upgrade
apt-get -f install (to clean up any messes)
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>
Old way
On the computer you will be ssh-ing from type:
> ssh-keygen -t dsa
(don't enter a password)
Then, copy the created ~/.ssh/id_dsa.pub file to the server you wish to ssh into.
> scp ~/.ssh/id_dsa.pub [server]:~
Now switch over the computer you will be ssh-ing into and type:
> cat id_dsa.pub >> .ssh/authorized_keys