Posted in databases, scripting, Unix

Unix – I did my best

1nnpyr

Hi Boys and Girls!

After my previous Unix-related post some of you complained that it was too short, to little knowledge and more meh than wow. This time I decided to do my best and fulfill all your Unix desires ūüôā

One of my biggest discoveries about Unix (and command line in general) is that
YOU HAVE TO KNOW.

You have to know where your file is.

You have to know what is the path to the folder in which your file would be stored.

You have to know how to do things.

In order to know things – I’ve gathered bunch of tips and commands that might be useful. ūüôā

At first – commands!

File management:

  • cat –¬†Concatenate and print files
  • chgrp –¬†Change the file group ownership
  • chmod –¬†Change the file modes/attributes/permissions
  • chown –¬†Change the file ownership
  • chattr – ¬†Change file attributes
  • cd ¬† – Change directory
  • cd – – Change to previous directory

(hint: cd without provided directory will take you back to home catalog – with the specified path will take you to that directory.

It is also possible to move up step by step or several parent directories at once, for example:

cd ../../../   Рwill move you 3 cataloges up)

  • df –¬†Report free disk space
  • echo –¬†Write arguments to standard output
  • file – ¬†Determine file type
  • find – ¬†Find files
  • gzip – Zip files
  • gunzip – Unzip files
  • ln¬† –¬†Link files
  • ls – List directory contents

(ls –color will list your files with selected color)

  • mkdir –¬†Make directories
  • more –¬†Display files on a page-by-page basis
  • mv –¬†Move or rename files

For examlpe Рif you wanna rename test1 file into test45 Рyour command would be like this:   mv test1 test45

  • pwd –¬†print working directory – Return working directory name
  • rcp – Transfer files to the remote host
  • rm – Remove files and catalogs
  • rmdir – Remove directories, if they are empty.
  • split –¬†Split files into pieces
  • touch –¬†Change file access and modification times
  • umask –¬†Get or set the file mode creation mask
  • unlink –¬†Call the unlink function

File system management:

  • badblocks – badblocks control
  • df – Report free disk space
  • dd –¬†Convert and copy a file

Process management:

  • at –¬†Execute commands at a later time
  • cron – Regular process run during¬†given timeframe.
  • fg –¬†Run jobs in the foreground
  • kill –¬†Terminate or signal process.
  • killall –¬†Terminate or signal all processes with given name.

Sounds Metallica-ish, doesn’t it?

  • ps –¬†Report process status
  • watch – Monitor command result

(For the watch ūüėČ )

  • nice –¬†Invoke a utility with an altered nice value

Users and systems management:

  • clear – Clear console / terminal
  • login – Log in to the system
  • passwd – Change password
  • su – Log into other user’s account
  • sudo – Run process with root rights
  • who –¬†Display who is on the system
  • whoami –¬†Display¬†what user are you currently using

Text editing:

  • cut –¬†Cut out selected fields of each line of a file
  • grep –¬†Search text for a pattern
  • head –¬†Copy the first part of files
  • more –¬†Display files on a page-by-page basis
  • vi –¬†Screen-oriented (visual) display editor

Comment time

People usually don’t know all Unix commands by heart – they collect the most useful ones in random txt file and use them (or use history command), believe me. To use Unix – you don’t have to know them all. Take it easy.

To manage your Unix account – you’ll need a login and password. Nice tool to manage Unix (or Linux) commands is Putty¬†(such fabulous UI design) – give it a try ūüôā

Command line allows you to combine multiple commands and get precise results.

On the other hand, you may be thinking how Unix will be helpful in testing activities? In the same way as in development – you are able to manage your files quickly or run shell scripts. In addition, everyone is able go through the same logs, search for useful scripts, go inside them, look around and modify, if necessary.

You can also narrow down your search results, using grep, or make sure that the log you are looking for at the moment is the same one, which has been generated
a moment ago – not last month.

Furthermore, you are able to color your results, number the rows and save all modifications. All of that  Рusing just pure commands Рwithout GUI. Sounds strange Рbut it works Рand, to be honest, a lot of people work this way.

One account – multiple users

There is a very important thing to remember when working on Unix account.

I did mention before – companies (projects) use Unix or Linux, because it is possible to work on the remote machine – even by multiple users at once. On the other hand, those users usually have rights to modify the same files. What dose it mean? You have to be precise and careful what you are doing.

I hope that my guide made you curious and you’ll experiment with Unix, Linux and command line. It is not as scary as you think.

Do you have any favorite commands? Did I miss something important?¬†Don’t be shy – you can comment down below.

Stalk me on Twitter (@KingaTest).

Cheers!

Posted in scripting, Unix

Unix and friends

UNIX

Knowing Unix command line is definitely not something that you’ll impress a nice girl, but it might be something that you’ll impress cute geek guy ūüėČ

What is Unix

As I wrote before¬†¬†Unix¬†is a family of multitasking, multi user computer operating systems. I was told that my definition was not precise enough, so for those of you, who are completely not familiar with Unix, I’ll repeat:

Unix is a OS (Operation System).

It is not a tool.

It consists of large number of tools.

It’s like a mother-ship for other OSes (such as Linux or you’re favorite Mac ūüėČ ).

In order to talk to Unix – you’ll need to be using the¬†command line.

(I hope this time it was explicit enough :)).

crVtQK

Moving on

In Unix-like systems the commands are quite often nothing else but tiny programs, which run from command line. They are form of shells. Most of the shells can be also used as scripting language, which enables the user to perform multiple tasks and write scripts to automate repetitive activities.

There is several scripting languages available (csh, ksh, bash). As far as I know, one of the most popular in Unix is bash.

Before you start a little chit chat with your console – it is good to know¬†the basics – and what I mean by that is to read about FHS –¬†Filesystem Hierarchy Standars.¬†Unless you won’t be a smart-ass.

FHS is common for Linux and Unix systems.

Examples

Having said that, let’s move on to¬†the most useful commands that allow you talk¬†to Unix.

One of the cutest commands I’ve ever seen is whoami. It is a real command. It doesn’t mean that¬†Unix would reveal the secrets of life in front of you, but after several hours of coding it is good to know your name, right?

What might be more useful in real life? What do I use on daily basis?

bash  Рswitch scripting language to bash

pwd – show current directory

cat   Рshow file content

cd    Рchange directory

/       Рhint Рin Unix (in a contrary to Windows console) we use / instead of \

cp  Рcopy

ls   Рlist

ls -l   Рlist with rights Рthis command shows hidden rights to the files inside current catalog

 -a   Рlist hidden files

ln  Рcreate hard link

rm – remove file or catalog

chmod  Рadding/removing rights to the files

-al      Рshow hidden catalogs

history – this one fellow might be useful at the beginning – it lists all previous commands

Please try it at home. Next time we’ll play a bit more with Unix. I’ll show you some tricks.

As usual, stalk me on Twitter – all of your comments are very welcome.

Cheers!