Vim Tips

1. remove the last character, if it presents in vim: The following commandremoves the "," from the end of the line if it presents.
:%s/,$//g
2. ^M in vim
to remove the ^M use %s/+ //g
press ctrl+v key and then hit Enter key to input ^M in vim command mode.
3. Replace ^with #:
:set number
:10,12s/^/#

Finish replacing you may find that the first column of the file is still inhighlight mode, to clear:

use :noh

Vim Tips

1. remove the last character, if it presents in vim: The following command removes the "," from the end of the line if it presents.
:%s/,$//g
2. ^M in vim
to remove the ^M use %s/<ctrl+V>+ <Enter>//g
press ctrl+v key and then hit Enter key to input ^M in vim command mode.
3. Replace ^with #:
:set number
:10,12s/^/#

Finish replacing you may find that the first column of the file is still in highlight mode, to clear:

use :noh

Add printer with Tomato USB on Asus to MacOSX

Add printer >> JetDirect Printer >> put down the router's IP address and port number 9100, 192.168.1.1:9100 >> from the dropdown list to find your printer's driver

Add printer with Tomato USB on Asus to MacOSX

Add printer >> JetDirect Printer >> put down the router's IP address and port number 9100, 192.168.1.1:9100 >> from the dropdown list to find your printer's driver

Linux System Admin Tool Box

1. See user login history

$ last: listing most recent logins by users.


$ last -a list the IP or name of the system from where the user logged in

2. Vied the currently logged in user

$ who: list logged in users and their process


$ users: only list the logged in users

3. Running procssses of logged in user

$ w : who is logged in and what they are doing now.

4. Others

$ uptime: tell how long the system has been running

$ id: display user and all group ids


$ free

$ du

$ df

$ env

$ ps

$ top

 

 

 

 

 

Linux System Admin Tool Box

1. See user login history

$ last: listing most recent logins by users.


$ last -a list the IP or name of the system from where the user logged in

2. Vied the currently logged in user

$ who: list logged in users and their process


$ users: only list the logged in users

3. Running procssses of logged in user

$ w : who is logged in and what they are doing now.

4. Others

$ uptime: tell how long the system has been running

$ id: display user and all group ids


$ free

$ du

$ df

$ env

$ ps

$ top

Linux System Admin Tool Box

1. See user login history

$ last: listing most recent logins by users.


$ last -a list the IP or name of the system from where the user logged in

2. Vied the currently logged in user

$ who: list logged in users and their process


$ users: only list the logged in users

3. Running procssses of logged in user

$ w : who is logged in and what they are doing now.

4. Others

$ uptime: tell how long the system has been running

$ id: display user and all group ids


$ free

$ du

$ df

$ env

$ ps

$ top

Linux System Admin Tool Box

1. See user login history

$ last: listing most recent logins by users.


$ last -a list the IP or name of the system from where the user logged in

2. Vied the currently logged in user

$ who: list logged in users and their process


$ users: only list the logged in users

3. Running procssses of logged in user

$ w : who is logged in and what they are doing now.

4. Others

$ uptime: tell how long the system has been running

$ id: display user and all group ids


$ free

$ du

$ df

$ env

$ ps

$ top

 

 

 

 

 

Use Curl to batch download files from a website

In this example, we suppose all the files are in the same folder on the website and the file names have the same pattern:

$ curl -L -O http://www.example site.com/color/pic/fire[1-5].gif

-L : Follows all redirections until the final destination page is found. This switch is almost always required as curl won’t follow redirects by default (read about how to check the server http headers with curl).
-O : By using this switch you instruct curl to save the downloaded data to a file in the current directory. The filename of the remote file is used. This switch is also required or else curl will print the data to stdout, which is something you won’t probably like.


wget all files of the same type

To get all the pdf files:this command does not work on all websites.

$ wget -r -l1 –no-parent -A.pdf 

Use Curl to batch download files from a website

In this example, we suppose all the files are in the same folder on the website and the file names have the same pattern:

$ curl -L -O http://www.example site.com/color/pic/fire[1-5].gif

-L : Follows all redirections until the final destination page is found. This switch is almost always required as curl won’t follow redirects by default (read about how to check the server http headers with curl).
-O : By using this switch you instruct curl to save the downloaded data to a file in the current directory. The filename of the remote file is used. This switch is also required or else curl will print the data to stdout, which is something you won’t probably like.


wget all files of the same type

To get all the pdf files:this command does not work on all websites.

$ wget -r -l1 –no-parent -A.pdf  <url>

CentOS user and group, Create user and add it to the sudoers list

Create user and add to the exiting group:

/usr/sbin/useradd -G {group-name} username

if the group does not exist, create it first:

/usr/sbin/groupadd group_name

If you do not use the group option then the user will be assigned to the group with the same name user name.

Remove a user:

sudo /usr/sbin/userdel

usr -r option if you also want to delete the user's home folder

User and group related files:

cat /etc/passwd

cat /etc/group

Example:

Create a user and add the user to the sudoers list: Use root account to do the following steps


1. create sudoers group: /usr/sbin/groupadd sudoers


2. create user: /usr/sbin/useradd -G sudoers htang

3.  modify the /etc/sudoers file bu adding the write attribute

chmod +w /etc/sudoers

4. modify the following lines:

## Allows people in group wheel to run all commands
#%wheel ALL=(ALL)    ALL

to

## Allows people in group wheel to run all commands
%sudoers  ALL=(ALL)    ALL

change the %wheel to %sudoers and remove the comment

5. remove the write attribute of /etc/sudoers file

chmod -w /etc/sudoers

CentOS user and user group

Create user and add to the esiting group:

/usr/sbin/useradd -G {group-name} username

if the group does not exist, create it first:

groupadd group_name

If you do not use the group option then the user will be assigned to thegroup with the same name user name.

Remove a user:

sudo /usr/sbin/userdel

User and group related files:

cat /etc/passwd

cat /etc/gshdow

Configuring Samba on CentOS

1 .Installing samba via yum

yum -y install samba samba-common samba-client

Configuring samba. Before changing the configure file, back up the original file:

cp /etc/samba/smb.conf /etc/samba/smb.conf.orig

1.1 Examples on setting password protected Samba share

vi /etc/samba/smb.conf


[global]
workgroup = WORKGROUP
server string = ncu12345678
security = User 
load printers = yes
cups options = raw
[share]
writeable = yes
path = /home/ajohn/dataswitch/windows
#do not use this setting since it will cause all created files owned by root
#admin users = user
force user = ajohn
valid users = ajohn
public = yes
available = yes
guest ok = no
# I changes the permissions to rw-rw-r--
create mask = 664
force create mode = 664
security mask = 664
force security mode = 664

directory mask = 0775
force directory mode = 0775
directory security mask = 0775
force directory security mode = 0775


Save and exit the configuration file.



2. Create Samba User

After you have install samba sever, yous still can’t login samba server. You will need create a samba user :
smbpasswd -a username
‘-a’ switch tell smbpasswd we want to add a new user, username is the user you want to add.

Please take note, username must exist in /etc/passwd file or you will need use ‘useradd’ to create a user in Linux :

sudo /usr/sbin/useradd -d /home/username -s /bin/false -n username
 
This will create a new user with same group name with (told by ‘-n’), but the user can’t login and run any shell command (because you have specfic the login shell is /bin/false by the ‘-s’ switch, if you want allow user to able to login to a shell, replace /bin/false with /bin/sh).

Ok now you have create a new samba user, how about you want delete or disable them? ‘-d’ switch will disable the user to login to samba server:
smbpasswd -d username
If you want to delete a user permanently:
smbpasswd -x username
3. Start the Samba service

sudo /etc/init.d/smb start

Question: If you encounter "access denied error"? check whether you have set SeLinux to disabled or permissive

Configuring Samba on CentOS

1 .Installing samba via yum


yum -y install samba samba-common samba-client


Configuring samba. Before changing the configure file, back up the original file:


cp /etc/samba/smb.conf /etc/samba/smb.conf.orig


Showing you the basic configuration of samba. In this example we are going to share softwares directory. Only samba user can able to save files in this directory.


vi /etc/samba/smb.conf

[global]
workgroup = WORKGROUP
server string =String used to show
security = share
load printers = yes
cups options = raw
[share]
writeable = yes
admin users = emen
path = /softwares
force user = root
valid users = emen
public = yes
available = yes



Save and exit the configuration file.






2. Create Samba User


After you have install samba sever, yous still can’t login samba server. You will need create a samba user :

$ smbpasswd -a username

‘-a’ switch tell smbpasswd we want to add a new user, username is the user you want to add.If you want use your windows login password to log in to samba server, you can define the password as your windows password here. The problem is that you need change your samba server password accordingly when you change your windows password.


Please take note, username must exist in /etc/passwd file or you will need use ‘useradd’ to create a user in Linux :

$ sudo /usr/sbin/useradd -d /home/username -s /bin/false -n username
 

This will create a new user with same group name with (told by ‘-n’), but the user can’t login and run any shell command (because you have specfic the login shell is /bin/false by the ‘-s’ switch, if you want allow user to able to login to a shell, replace /bin/false with /bin/sh).


Ok now you have create a new samba user, how about you want delete or disable them? ‘-d’ switch will disable the user to login to samba server:

$ smbpasswd -d username

If you want to delete a user permanently:

$ smbpasswd -x username

3. Configure iptables to allow conection to the samba server

Check to see whether you have port 137,138,139,443 and 445 open for connection. If not open them in iptables.

$ sudo vim /etc/sysconfig/iptables

$ sudo /etc/init.d/iptables restart

4. Start the Samba service


$ sudo /etc/init.d/smb start

$ sudo /sbin/chkconfig smb on

Add other language support for CentOS

By default, CenOS does not install other languages, to install you can use the following command:

sudo yum install @chinese-support

Add other language support for CentOS

By default, CenOS does not install other languages, to install you can use the following command:

sudo yum install @chinese-support

Datatable static image not found on the server

When you use ```datatables.min.css``` and ```datatables.min.js``` locally, instead of datatables CDN, you may have encountered that ```sort...