Jump to content
Sign in to follow this  
Coniesan

[FreeBSD] Helpful tricks

Recommended Posts

Hey @ all,

I hope a thread like this doesn't exist right now!

Introduction:

Here u'll find some basics you should know, and some things which makes your life easier!

So let's go:

First of all, the command-line! If you often uses putty (or s.th. else) it helped me a lot to change the default prompt!

Here my favorite:

comando.png

You only have to edit the .cshrc file in your <user> (for example /root or /home/<user>) directory!

Uncomment the given prompt line, or delete it and put the following instead:

set prompt = "%{033[31m%}%n %{033[1;33m%}%~ %{033[0m%}>"

Second thing is the SCP Service! Most of u know "winscp" which is based on the unix scp service!

With this, you easy can transfer files between you servers and you don't have to copy it first on your computer!

For example, we take the file.tgz from out SOURCE server, to our system into the direcory we are at the moment:

scp -P <port> <user>@xxx.xxx.xx.xxx:<path_to_file> <path_where_to_save_file>
If you are using a SSH-Key on the external server, you have to edit your command, and add the .ppk file to it:

scp -P <port> -i <path_to_private_key> <user>@xxx.xxx.xx.xxx:<path_to_file> <path_where_to_save_file>
(the ppk should have 600 rights!)

If you need an example:

Take game.tgz from 10.2.0.1 in the /home directory to /usr/home

scp -P 22 root@10.2.0.1:/home/game.tgz /usr/home/
Take game.tgz from 10.2.0.1 in the /home directory to /usr/home, with the ppk in /home/my.ppk

scp -P 22 -i /home/my.ppk root@10.2.0.1:/home/game.tgz /usr/home/

Here some helpful commands:

-----------------------------------------------------------------------------------------------------------------

whereis

If you don't know, where you can find a package you can use it, to get the exact path

root / >whereis apache22
apache22: /usr/ports/www/apache22
-----------------------------------------------------------------------------------------------------------------

df

The df command shows you some informations about your hard disk space (the parameter -h is useful here)

root / >df -h
Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/da0s1a     17G    2.9G     13G    18%    /
devfs          1.0k    1.0k      0B   100%    /dev
/dev/da1s1d     77G    4.0k     71G     0%    /usr/home
-----------------------------------------------------------------------------------------------------------------

ps

ps shows you all running processes a user running at the moment!

You get the pid, the status, the time, a process is running, and the command or service which is executed!

[for Metin, if your came is named "game" and your server is running, you'll see there ./game for example)

root / >ps
  PID  TT  STAT      TIME COMMAND
  872  v0  Is+    0:00.00 /usr/libexec/getty Pc ttyv0
13771   0  Ss     0:00.04 -csh (csh)
13824   0  R+     0:00.00 ps
use the parameter -al, to get ALL processes listed

-----------------------------------------------------------------------------------------------------------------

kill

With kil you can kill a process by it's pid!

important parameters are -1 and -9!

-1: The kill stops the process and wait for the response, that it done everything well (saving files or s.th. else)

-9: The kill stops the process without asking anything! Just die is the slogan!

kill -9 <pid>
If you don't know the pid (but the name) or if you wanna kill a view processes with the same name (example Metin2 where you have the "game" for each Channel/Core) you can use killall!

Here same system with -1 and -9

killall -9 game
-----------------------------------------------------------------------------------------------------------------

ls

This command shows you every file in a directory.

ls -G
is painting files with special endings. Use the parameter -al to get ALL files listed ( .file are not listed with the single ls command)

-----------------------------------------------------------------------------------------------------------------

cat

It shows you the content of a file, without opening it in an editor!

In combination with the grep command, it's very easy to find a special sting in a file!

cat CONFIG
CHANNEL: 1
CHECK_MULTIHACK: 0
COMMON_SQL: localhost mt2 mt2!@# common
DB_ADDR: 127.0.0.1
DB_PORT: 13000
empire_whisper: 1
HOSTNAME: Game1
LOG_SQL: localhost mt2 mt2!@# log
MAP_ALLOW: 1 3 21 23 41 43 61 62 63 64 65
....(and so on)
-----------------------------------------------------------------------------------------------------------------

grep|egrep

It can be used additionaly to an other command or alone to "grep" s.th. out, what you are looking for!

For example (combination with "cat"):

cat CONFIG | grep "PORT"
DB_PORT: 15000
P2P_PORT: 161000
PORT: 13000
Or if you looking for a file with includes a special string:

grep -r "text string to search” directory-path
-----------------------------------------------------------------------------------------------------------------

cp/mv

With cp you can copy with mv move a file!

cp [source] [target]
mv [source] [target]
To copy/move a whole directory, you need to add the parameter -R

cp -R [source] [target]
mv -R [source] [target]
-----------------------------------------------------------------------------------------------------------------

rm

Use it to delete files

rm <file>
If you need to delete a whole direcotory add the parameter -rf (it is much more faster then deleting it by FileZilla or WinSCP)

rm -rf <file/directory>
-----------------------------------------------------------------------------------------------------------------

touch/mkdir

To create a new file without editing it, use touch. With mkdir you create a new directory.

touch <file-path>
mkdir <directory-path>
-----------------------------------------------------------------------------------------------------------------

tar

For packing or extracting with compression you can use this basic command.

I allways use it the the following parameters:

To pack:

tar czvf datei.tgz directory
To extract:

tar xzvf file.tgz
-----------------------------------------------------------------------------------------------------------------

pkg_info

This command shows you every package you have installed

-----------------------------------------------------------------------------------------------------------------

find

with find, you are able to search quickly for a file by its name and get the exact path.

For example "syserr"

find / -name "syserr"
You are also able to execute a command if it finds s.th.

For example, we delete the syserr while searching, if we find one

find . -name syserr -exec rm {} ;

To get all important CPU informations, you can use this:

sysctl -a | egrep -i 'hw.machine|hw.model|hw.ncpu'
hw.machine: amd64
hw.model: Intel(R) Xeon(R) CPU E5-2640 0 @ 2.50GHz
hw.ncpu: 3
hw.machine_arch: amd64

If you wanna know s.th. about your used memory(RAM/SWAP) and so on, you can install "free" (which is a basic command on linux)

It's an perl script, so you have to install perl if you doesn't

fetch http://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
mv freebsd-memory.pl.txt /usr/local/bin/free
chmod +x /usr/local/bin/free
Command (possible output):

free
SYSTEM MEMORY INFORMATION:
mem_wire:         390885376 (    372MB) [ 18%] Wired: disabled for paging out
mem_active:  +    805543936 (    768MB) [ 38%] Active: recently referenced
mem_inactive:+    809562112 (    772MB) [ 39%] Inactive: recently not referenced
mem_cache:   +     31989760 (     30MB) [  1%] Cached: almost avail. for allocation
mem_free:    +     29843456 (     28MB) [  1%] Free: fully available for allocation
mem_gap_vm:  +       581632 (      0MB) [  0%] Memory gap: UNKNOWN
-------------- ------------ ----------- ------
mem_all:     =   2068406272 (   1972MB) [100%] Total real memory managed
mem_gap_sys: +     63307776 (     60MB)        Memory gap: Kernel?!
-------------- ------------ -----------
mem_phys:    =   2131714048 (   2032MB)        Total real memory available
mem_gap_hw:  +     15769600 (     15MB)        Memory gap: Segment Mappings?!
-------------- ------------ -----------
mem_hw:      =   2147483648 (   2048MB)        Total real memory installed

SYSTEM MEMORY SUMMARY:
mem_used:        1276088320 (   1216MB) [ 59%] Logically used memory
mem_avail:   +    871395328 (    831MB) [ 40%] Logically available memory
-------------- ------------ ----------- ------
mem_total:   =   2147483648 (   2048MB) [100%] Logically total memory

One more thing is the traffic!

To get a screen like this:

darkstat.png

1. Install:

cd /usr/ports/net-mgmt/darkstat && make install clean
2. Enable in /etc/rc.conf our example network interface is em0

darkstat_enable="YES"
darkstat_interface="em0"
3. start the service

service darkstat start
4. start a session (port is not for listening It's for the web-application)

darkstat -p <port> -b <server_ip> -i <network_interface>
you will see your stats on: <server_ip>:<port>

For example:

darkstat -p 10010 -b 10.5.0.2 -i em0
now go on http://10.5.0.2:10010

Kind regards

  • Love 7

Share this post


Link to post

Didn't know it was possible to make free work on freebsd, hadn't considered searching for a way to do it. Cool :>

The prompt change is nice too, but can't seem to make that work for regular users. I modified the ".cshrc" file in the /usr/home/username" directory.

  • Love 1

Share this post


Link to post

I thought, this are the basics you should know if you work with the command line...!

You can use almost everything on linux systems, too (some even on windows)

 

If someone have a command, or an other question, how he/she can do anything with command line, I'll in the future add commands and/or ways how to do or deal with it

#Edit: Thanks, my mistake, edited it ;)

Share this post


Link to post

I thought, this are the basics you should know if you work with the command line...!

You can use almost everything on linux systems, too (some even on windows)

 

If someone have a command, or an other question, how he/she can do anything with command line, I'll in the future add commands and/or ways how to do or deal with it

#Edit: Thanks, my mistake, edited it ;)

no, my point was I tried it on a regular user but it didn't work. It works on root.

Share this post


Link to post

Try this:

env | grep -i shell

the output should be:

SHELL=/bin/csh

But the default output (for normal useres) is:

SHELL=/bin/sh

Execute this in command line:

chsh -s /bin/csh

And the prompt will change after su or relogg on the user ;)
Like this:

shell_change.png

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.